diff options
author | Steven Rostedt <rostedt@goodmis.org> | 2016-04-14 12:15:22 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2016-06-20 09:54:17 -0400 |
commit | d8275c454dcdba296675221b4c12f19d1b6e0ee8 (patch) | |
tree | c45950295f659f86cb67b7d8f035663b98840e9a | |
parent | 4e267db135c44d0b18e553899fe7df32b89211a5 (diff) |
tracing: Move filtered_pid helper functions into trace.c
As the filtered_pid functions are going to be used by function tracer as
well as trace_events, move the code into the generic trace.c file.
The functions moved are:
trace_find_filtered_pid()
trace_ignore_this_task()
trace_filter_add_remove_task()
Kernel Doc text was also added.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | kernel/trace/trace.c | 78 | ||||
-rw-r--r-- | kernel/trace/trace_events.c | 51 |
2 files changed, 78 insertions, 51 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8a4bd6b68a0b..0b87fe8e6d0b 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -319,6 +319,84 @@ int call_filter_check_discard(struct trace_event_call *call, void *rec, | |||
319 | return 0; | 319 | return 0; |
320 | } | 320 | } |
321 | 321 | ||
322 | /** | ||
323 | * trace_find_filtered_pid - check if a pid exists in a filtered_pid list | ||
324 | * @filtered_pids: The list of pids to check | ||
325 | * @search_pid: The PID to find in @filtered_pids | ||
326 | * | ||
327 | * Returns true if @search_pid is fonud in @filtered_pids, and false otherwis. | ||
328 | */ | ||
329 | bool | ||
330 | trace_find_filtered_pid(struct trace_pid_list *filtered_pids, pid_t search_pid) | ||
331 | { | ||
332 | /* | ||
333 | * If pid_max changed after filtered_pids was created, we | ||
334 | * by default ignore all pids greater than the previous pid_max. | ||
335 | */ | ||
336 | if (search_pid >= filtered_pids->pid_max) | ||
337 | return false; | ||
338 | |||
339 | return test_bit(search_pid, filtered_pids->pids); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * trace_ignore_this_task - should a task be ignored for tracing | ||
344 | * @filtered_pids: The list of pids to check | ||
345 | * @task: The task that should be ignored if not filtered | ||
346 | * | ||
347 | * Checks if @task should be traced or not from @filtered_pids. | ||
348 | * Returns true if @task should *NOT* be traced. | ||
349 | * Returns false if @task should be traced. | ||
350 | */ | ||
351 | bool | ||
352 | trace_ignore_this_task(struct trace_pid_list *filtered_pids, struct task_struct *task) | ||
353 | { | ||
354 | /* | ||
355 | * Return false, because if filtered_pids does not exist, | ||
356 | * all pids are good to trace. | ||
357 | */ | ||
358 | if (!filtered_pids) | ||
359 | return false; | ||
360 | |||
361 | return !trace_find_filtered_pid(filtered_pids, task->pid); | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * trace_pid_filter_add_remove - Add or remove a task from a pid_list | ||
366 | * @pid_list: The list to modify | ||
367 | * @self: The current task for fork or NULL for exit | ||
368 | * @task: The task to add or remove | ||
369 | * | ||
370 | * If adding a task, if @self is defined, the task is only added if @self | ||
371 | * is also included in @pid_list. This happens on fork and tasks should | ||
372 | * only be added when the parent is listed. If @self is NULL, then the | ||
373 | * @task pid will be removed from the list, which would happen on exit | ||
374 | * of a task. | ||
375 | */ | ||
376 | void trace_filter_add_remove_task(struct trace_pid_list *pid_list, | ||
377 | struct task_struct *self, | ||
378 | struct task_struct *task) | ||
379 | { | ||
380 | if (!pid_list) | ||
381 | return; | ||
382 | |||
383 | /* For forks, we only add if the forking task is listed */ | ||
384 | if (self) { | ||
385 | if (!trace_find_filtered_pid(pid_list, self->pid)) | ||
386 | return; | ||
387 | } | ||
388 | |||
389 | /* Sorry, but we don't support pid_max changing after setting */ | ||
390 | if (task->pid >= pid_list->pid_max) | ||
391 | return; | ||
392 | |||
393 | /* "self" is set for forks, and NULL for exits */ | ||
394 | if (self) | ||
395 | set_bit(task->pid, pid_list->pids); | ||
396 | else | ||
397 | clear_bit(task->pid, pid_list->pids); | ||
398 | } | ||
399 | |||
322 | static cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu) | 400 | static cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu) |
323 | { | 401 | { |
324 | u64 ts; | 402 | u64 ts; |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index b5e514c4dada..a11e6d9a3841 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -502,57 +502,6 @@ static void ftrace_clear_events(struct trace_array *tr) | |||
502 | /* Shouldn't this be in a header? */ | 502 | /* Shouldn't this be in a header? */ |
503 | extern int pid_max; | 503 | extern int pid_max; |
504 | 504 | ||
505 | /* Returns true if found in filter */ | ||
506 | bool | ||
507 | trace_find_filtered_pid(struct trace_pid_list *filtered_pids, pid_t search_pid) | ||
508 | { | ||
509 | /* | ||
510 | * If pid_max changed after filtered_pids was created, we | ||
511 | * by default ignore all pids greater than the previous pid_max. | ||
512 | */ | ||
513 | if (search_pid >= filtered_pids->pid_max) | ||
514 | return false; | ||
515 | |||
516 | return test_bit(search_pid, filtered_pids->pids); | ||
517 | } | ||
518 | |||
519 | bool | ||
520 | trace_ignore_this_task(struct trace_pid_list *filtered_pids, struct task_struct *task) | ||
521 | { | ||
522 | /* | ||
523 | * Return false, because if filtered_pids does not exist, | ||
524 | * all pids are good to trace. | ||
525 | */ | ||
526 | if (!filtered_pids) | ||
527 | return false; | ||
528 | |||
529 | return !trace_find_filtered_pid(filtered_pids, task->pid); | ||
530 | } | ||
531 | |||
532 | void trace_filter_add_remove_task(struct trace_pid_list *pid_list, | ||
533 | struct task_struct *self, | ||
534 | struct task_struct *task) | ||
535 | { | ||
536 | if (!pid_list) | ||
537 | return; | ||
538 | |||
539 | /* For forks, we only add if the forking task is listed */ | ||
540 | if (self) { | ||
541 | if (!trace_find_filtered_pid(pid_list, self->pid)) | ||
542 | return; | ||
543 | } | ||
544 | |||
545 | /* Sorry, but we don't support pid_max changing after setting */ | ||
546 | if (task->pid >= pid_list->pid_max) | ||
547 | return; | ||
548 | |||
549 | /* "self" is set for forks, and NULL for exits */ | ||
550 | if (self) | ||
551 | set_bit(task->pid, pid_list->pids); | ||
552 | else | ||
553 | clear_bit(task->pid, pid_list->pids); | ||
554 | } | ||
555 | |||
556 | static void | 505 | static void |
557 | event_filter_pid_sched_process_exit(void *data, struct task_struct *task) | 506 | event_filter_pid_sched_process_exit(void *data, struct task_struct *task) |
558 | { | 507 | { |