Skip to content

Commit fe014e2

Browse files
committed
ftrace: Convert the rest of the function trigger over to the mapping functions
As the data pointer for individual ips will soon be removed and no longer passed to the callback function probe handlers, convert the rest of the function trigger counters over to the new ftrace_func_mapper helper functions. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 1a93f8b commit fe014e2

1 file changed

Lines changed: 85 additions & 38 deletions

File tree

‎kernel/trace/trace_functions.c‎

Lines changed: 85 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,12 @@ static struct tracer function_trace __tracer_data =
267267
};
268268

269269
#ifdef CONFIG_DYNAMIC_FTRACE
270-
static void update_traceon_count(void **data, bool on)
270+
static void update_traceon_count(struct ftrace_probe_ops *ops,
271+
unsigned long ip, bool on)
271272
{
272-
long *count = (long *)data;
273-
long old_count = *count;
273+
struct ftrace_func_mapper *mapper = ops->private_data;
274+
long *count;
275+
long old_count;
274276

275277
/*
276278
* Tracing gets disabled (or enabled) once per count.
@@ -301,7 +303,10 @@ static void update_traceon_count(void **data, bool on)
301303
* setting the tracing_on file. But we currently don't care
302304
* about that.
303305
*/
304-
if (!old_count)
306+
count = (long *)ftrace_func_mapper_find_ip(mapper, ip);
307+
old_count = *count;
308+
309+
if (old_count <= 0)
305310
return;
306311

307312
/* Make sure we see count before checking tracing state */
@@ -315,10 +320,6 @@ static void update_traceon_count(void **data, bool on)
315320
else
316321
tracing_off();
317322

318-
/* unlimited? */
319-
if (old_count == -1)
320-
return;
321-
322323
/* Make sure tracing state is visible before updating count */
323324
smp_wmb();
324325

@@ -329,14 +330,14 @@ static void
329330
ftrace_traceon_count(unsigned long ip, unsigned long parent_ip,
330331
struct ftrace_probe_ops *ops, void **data)
331332
{
332-
update_traceon_count(data, 1);
333+
update_traceon_count(ops, ip, 1);
333334
}
334335

335336
static void
336337
ftrace_traceoff_count(unsigned long ip, unsigned long parent_ip,
337338
struct ftrace_probe_ops *ops, void **data)
338339
{
339-
update_traceon_count(data, 0);
340+
update_traceon_count(ops, ip, 0);
340341
}
341342

342343
static void
@@ -379,47 +380,56 @@ static void
379380
ftrace_stacktrace_count(unsigned long ip, unsigned long parent_ip,
380381
struct ftrace_probe_ops *ops, void **data)
381382
{
382-
long *count = (long *)data;
383+
struct ftrace_func_mapper *mapper = ops->private_data;
384+
long *count;
383385
long old_count;
384386
long new_count;
385387

388+
if (!tracing_is_on())
389+
return;
390+
391+
/* unlimited? */
392+
if (!mapper) {
393+
trace_dump_stack(STACK_SKIP);
394+
return;
395+
}
396+
397+
count = (long *)ftrace_func_mapper_find_ip(mapper, ip);
398+
386399
/*
387400
* Stack traces should only execute the number of times the
388401
* user specified in the counter.
389402
*/
390403
do {
391-
392-
if (!tracing_is_on())
393-
return;
394-
395404
old_count = *count;
396405

397406
if (!old_count)
398407
return;
399408

400-
/* unlimited? */
401-
if (old_count == -1) {
402-
trace_dump_stack(STACK_SKIP);
403-
return;
404-
}
405-
406409
new_count = old_count - 1;
407410
new_count = cmpxchg(count, old_count, new_count);
408411
if (new_count == old_count)
409412
trace_dump_stack(STACK_SKIP);
410413

414+
if (!tracing_is_on())
415+
return;
416+
411417
} while (new_count != old_count);
412418
}
413419

414-
static int update_count(void **data)
420+
static int update_count(struct ftrace_probe_ops *ops, unsigned long ip)
415421
{
416-
unsigned long *count = (long *)data;
422+
struct ftrace_func_mapper *mapper = ops->private_data;
423+
long *count = NULL;
417424

418-
if (!*count)
419-
return 0;
425+
if (mapper)
426+
count = (long *)ftrace_func_mapper_find_ip(mapper, ip);
420427

421-
if (*count != -1)
428+
if (count) {
429+
if (*count <= 0)
430+
return 0;
422431
(*count)--;
432+
}
423433

424434
return 1;
425435
}
@@ -428,7 +438,7 @@ static void
428438
ftrace_dump_probe(unsigned long ip, unsigned long parent_ip,
429439
struct ftrace_probe_ops *ops, void **data)
430440
{
431-
if (update_count(data))
441+
if (update_count(ops, ip))
432442
ftrace_dump(DUMP_ALL);
433443
}
434444

@@ -437,22 +447,26 @@ static void
437447
ftrace_cpudump_probe(unsigned long ip, unsigned long parent_ip,
438448
struct ftrace_probe_ops *ops, void **data)
439449
{
440-
if (update_count(data))
450+
if (update_count(ops, ip))
441451
ftrace_dump(DUMP_ORIG);
442452
}
443453

444454
static int
445455
ftrace_probe_print(const char *name, struct seq_file *m,
446-
unsigned long ip, void *data)
456+
unsigned long ip, struct ftrace_probe_ops *ops)
447457
{
448-
long count = (long)data;
458+
struct ftrace_func_mapper *mapper = ops->private_data;
459+
long *count = NULL;
449460

450461
seq_printf(m, "%ps:%s", (void *)ip, name);
451462

452-
if (count == -1)
453-
seq_puts(m, ":unlimited\n");
463+
if (mapper)
464+
count = (long *)ftrace_func_mapper_find_ip(mapper, ip);
465+
466+
if (count)
467+
seq_printf(m, ":count=%ld\n", *count);
454468
else
455-
seq_printf(m, ":count=%ld\n", count);
469+
seq_puts(m, ":unlimited\n");
456470

457471
return 0;
458472
}
@@ -461,55 +475,82 @@ static int
461475
ftrace_traceon_print(struct seq_file *m, unsigned long ip,
462476
struct ftrace_probe_ops *ops, void *data)
463477
{
464-
return ftrace_probe_print("traceon", m, ip, data);
478+
return ftrace_probe_print("traceon", m, ip, ops);
465479
}
466480

467481
static int
468482
ftrace_traceoff_print(struct seq_file *m, unsigned long ip,
469483
struct ftrace_probe_ops *ops, void *data)
470484
{
471-
return ftrace_probe_print("traceoff", m, ip, data);
485+
return ftrace_probe_print("traceoff", m, ip, ops);
472486
}
473487

474488
static int
475489
ftrace_stacktrace_print(struct seq_file *m, unsigned long ip,
476490
struct ftrace_probe_ops *ops, void *data)
477491
{
478-
return ftrace_probe_print("stacktrace", m, ip, data);
492+
return ftrace_probe_print("stacktrace", m, ip, ops);
479493
}
480494

481495
static int
482496
ftrace_dump_print(struct seq_file *m, unsigned long ip,
483497
struct ftrace_probe_ops *ops, void *data)
484498
{
485-
return ftrace_probe_print("dump", m, ip, data);
499+
return ftrace_probe_print("dump", m, ip, ops);
486500
}
487501

488502
static int
489503
ftrace_cpudump_print(struct seq_file *m, unsigned long ip,
490504
struct ftrace_probe_ops *ops, void *data)
491505
{
492-
return ftrace_probe_print("cpudump", m, ip, data);
506+
return ftrace_probe_print("cpudump", m, ip, ops);
507+
}
508+
509+
510+
static int
511+
ftrace_count_init(struct ftrace_probe_ops *ops, unsigned long ip,
512+
void **data)
513+
{
514+
struct ftrace_func_mapper *mapper = ops->private_data;
515+
516+
return ftrace_func_mapper_add_ip(mapper, ip, *data);
517+
}
518+
519+
static void
520+
ftrace_count_free(struct ftrace_probe_ops *ops, unsigned long ip,
521+
void **_data)
522+
{
523+
struct ftrace_func_mapper *mapper = ops->private_data;
524+
525+
ftrace_func_mapper_remove_ip(mapper, ip);
493526
}
494527

495528
static struct ftrace_probe_ops traceon_count_probe_ops = {
496529
.func = ftrace_traceon_count,
497530
.print = ftrace_traceon_print,
531+
.init = ftrace_count_init,
532+
.free = ftrace_count_free,
498533
};
499534

500535
static struct ftrace_probe_ops traceoff_count_probe_ops = {
501536
.func = ftrace_traceoff_count,
502537
.print = ftrace_traceoff_print,
538+
.init = ftrace_count_init,
539+
.free = ftrace_count_free,
503540
};
504541

505542
static struct ftrace_probe_ops stacktrace_count_probe_ops = {
506543
.func = ftrace_stacktrace_count,
507544
.print = ftrace_stacktrace_print,
545+
.init = ftrace_count_init,
546+
.free = ftrace_count_free,
508547
};
509548

510549
static struct ftrace_probe_ops dump_probe_ops = {
511550
.func = ftrace_dump_probe,
512551
.print = ftrace_dump_print,
552+
.init = ftrace_count_init,
553+
.free = ftrace_count_free,
513554
};
514555

515556
static struct ftrace_probe_ops cpudump_probe_ops = {
@@ -558,6 +599,12 @@ ftrace_trace_probe_callback(struct ftrace_probe_ops *ops,
558599
if (!strlen(number))
559600
goto out_reg;
560601

602+
if (!ops->private_data) {
603+
ops->private_data = allocate_ftrace_func_mapper();
604+
if (!ops->private_data)
605+
return -ENOMEM;
606+
}
607+
561608
/*
562609
* We use the callback data field (which is a pointer)
563610
* as our counter.

0 commit comments

Comments
 (0)