3 * modules/parser/features.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin: SWAP Parser implement
26 #include <linux/types.h>
27 #include <linux/module.h>
28 #include <ks_features/ks_features.h>
29 #include <us_manager/us_manager.h>
30 #include "parser_defs.h"
32 #include "msg_parser.h"
34 #include <sampler/swap_sampler_module.h>
35 #include <energy/swap_energy.h>
38 syscall_file = (1 << 10), /* File operation syscalls tracing */
39 syscall_ipc = (1 << 11), /* IPC syscall tracing */
40 syscall_process = (1 << 12), /* Process syscalls tracing */
41 syscall_signal = (1 << 13), /* Signal syscalls tracing */
42 syscall_network = (1 << 14), /* Network syscalls tracing */
43 syscall_desc = (1 << 15), /* Descriptor syscalls tracing */
44 context_switch = (1 << 16), /* Context switch tracing */
45 func_sampling = (1 << 19) /* Function sampling */
48 int set_us_inst(struct conf_data *conf)
57 int unset_us_inst(void)
66 int set_syscall_file(struct conf_data *conf)
70 ret = set_feature(FID_FILE);
75 int unset_syscall_file(void)
79 ret = unset_feature(FID_FILE);
84 int set_syscall_ipc(struct conf_data *conf)
88 ret = set_feature(FID_IPC);
93 int unset_syscall_ipc(void)
97 ret = unset_feature(FID_IPC);
102 int set_syscall_process(struct conf_data *conf)
106 ret = set_feature(FID_PROCESS);
111 int unset_syscall_process(void)
115 ret = unset_feature(FID_PROCESS);
120 int set_syscall_signal(struct conf_data *conf)
124 ret = set_feature(FID_SIGNAL);
129 int unset_syscall_signal(void)
133 ret = unset_feature(FID_SIGNAL);
138 int set_syscall_network(struct conf_data *conf)
142 ret = set_feature(FID_NET);
147 int unset_syscall_network(void)
151 ret = unset_feature(FID_NET);
156 int set_syscall_desc(struct conf_data *conf)
160 ret = set_feature(FID_DESC);
165 int unset_syscall_desc(void)
169 ret = unset_feature(FID_DESC);
174 int set_context_switch(struct conf_data *conf)
178 ret = set_feature(FID_SWITCH);
183 int unset_context_switch(void)
187 ret = unset_feature(FID_SWITCH);
192 int set_func_sampling(struct conf_data *conf)
196 ret = swap_sampler_start(conf->data_msg_period);
201 int unset_func_sampling(void)
205 ret = swap_sampler_stop();
210 static int set_func_energy(struct conf_data *conf)
215 static int unset_func_energy(void)
221 struct feature_item {
223 int (*set)(struct conf_data *conf);
227 static struct feature_item feature_us_inst = {
228 .name = "user space instrumentation",
230 .unset = unset_us_inst
233 static struct feature_item feature_syscall_file = {
234 .name = "file operation syscalls",
235 .set = set_syscall_file,
236 .unset = unset_syscall_file
239 static struct feature_item feature_syscall_ipc = {
240 .name = "IPC syscall",
241 .set = set_syscall_ipc,
242 .unset = unset_syscall_ipc
245 static struct feature_item feature_syscall_process = {
246 .name = "process syscalls",
247 .set = set_syscall_process,
248 .unset = unset_syscall_process
251 static struct feature_item feature_syscall_signal = {
252 .name = "signal syscalls",
253 .set = set_syscall_signal,
254 .unset = unset_syscall_signal
257 static struct feature_item feature_syscall_network = {
258 .name = "network syscalls",
259 .set = set_syscall_network,
260 .unset = unset_syscall_network
263 static struct feature_item feature_syscall_desc = {
264 .name = "descriptor syscalls",
265 .set = set_syscall_desc,
266 .unset = unset_syscall_desc
269 static struct feature_item feature_context_switch = {
270 .name = "context switch",
271 .set = set_context_switch,
272 .unset = unset_context_switch
275 static struct feature_item feature_func_sampling = {
276 .name = "function sampling",
277 .set = set_func_sampling,
278 .unset = unset_func_sampling
281 static struct feature_item feature_func_energy = {
283 .set = set_func_energy,
284 .unset = unset_func_energy
287 static struct feature_item *feature_list[] = {
290 /* 2 */ &feature_us_inst,
298 /* 10 */ &feature_syscall_file,
299 /* 11 */ &feature_syscall_ipc,
300 /* 12 */ &feature_syscall_process,
301 /* 13 */ &feature_syscall_signal,
302 /* 14 */ &feature_syscall_network,
303 /* 15 */ &feature_syscall_desc,
304 /* 16 */ &feature_context_switch,
307 /* 19 */ &feature_func_sampling,
314 /* 26 */ &feature_func_energy
318 SIZE_FEATURE_LIST = sizeof(feature_list) / sizeof(struct feature_item *),
321 static u64 feature_inst = 0;
322 static u64 feature_mask = 0;
324 int init_features(void)
327 for (i = 0; i < SIZE_FEATURE_LIST; ++i) {
328 printk("### f init_feature_mask[%2d]=%p\n", i, feature_list[i]);
329 if (feature_list[i] != NULL) {
330 feature_mask |= ((u64)1) << i;
331 printk("### f name=%s\n", feature_list[i]->name);
338 void uninit_features(void)
342 int set_features(struct conf_data *conf)
346 u64 features, features_backup;
348 /* TODO: field use_features1 is not used*/
349 features_backup = features = conf->use_features0;
351 features &= feature_mask;
352 feature_XOR = features ^ feature_inst;
354 for (i = 0; feature_XOR && i < SIZE_FEATURE_LIST; ++i) {
355 if ((feature_XOR & 1) && feature_list[i] != NULL) {
358 ret = feature_list[i]->set(conf);
360 ret = feature_list[i]->unset();
363 char *func = features & 1 ? "set" : "unset";
364 print_err("%s '%s' ret=%d\n",
365 func, feature_list[i]->name, ret);
370 feature_inst = (feature_inst & f_mask) |
371 (features_backup & ~f_mask);