aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/ftrace.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-02-17 19:09:07 -0500
committerIngo Molnar <mingo@elte.hu>2009-02-17 19:09:07 -0500
commitac07bcaa8259841905ead3f8cd60b1923ca6c0e5 (patch)
tree162def1cd53ef477adca17fe06c33a484f6b2e87 /kernel/trace/ftrace.c
parent37bd824a35a60abc73e5fa8816bd5f50c913d69b (diff)
parent35ebf1caa4854ad5ba25f3a72967acc064147994 (diff)
Merge branch 'tip/tracing/ftrace' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace into tracing/ftrace
Diffstat (limited to 'kernel/trace/ftrace.c')
-rw-r--r--kernel/trace/ftrace.c102
1 files changed, 52 insertions, 50 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index aee95aea57e4..7dd5a2bef9cd 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -255,9 +255,9 @@ static struct pid * const ftrace_swapper_pid = &init_struct_pid;
255 255
256static struct hlist_head ftrace_func_hash[FTRACE_FUNC_HASHSIZE] __read_mostly; 256static struct hlist_head ftrace_func_hash[FTRACE_FUNC_HASHSIZE] __read_mostly;
257 257
258struct ftrace_func_hook { 258struct ftrace_func_probe {
259 struct hlist_node node; 259 struct hlist_node node;
260 struct ftrace_hook_ops *ops; 260 struct ftrace_probe_ops *ops;
261 unsigned long flags; 261 unsigned long flags;
262 unsigned long ip; 262 unsigned long ip;
263 void *data; 263 void *data;
@@ -460,8 +460,8 @@ static void ftrace_bug(int failed, unsigned long ip)
460static int 460static int
461__ftrace_replace_code(struct dyn_ftrace *rec, int enable) 461__ftrace_replace_code(struct dyn_ftrace *rec, int enable)
462{ 462{
463 unsigned long ip, fl;
464 unsigned long ftrace_addr; 463 unsigned long ftrace_addr;
464 unsigned long ip, fl;
465 465
466 ftrace_addr = (unsigned long)FTRACE_ADDR; 466 ftrace_addr = (unsigned long)FTRACE_ADDR;
467 467
@@ -530,9 +530,9 @@ __ftrace_replace_code(struct dyn_ftrace *rec, int enable)
530 530
531static void ftrace_replace_code(int enable) 531static void ftrace_replace_code(int enable)
532{ 532{
533 int failed;
534 struct dyn_ftrace *rec; 533 struct dyn_ftrace *rec;
535 struct ftrace_page *pg; 534 struct ftrace_page *pg;
535 int failed;
536 536
537 do_for_each_ftrace_rec(pg, rec) { 537 do_for_each_ftrace_rec(pg, rec) {
538 /* 538 /*
@@ -830,11 +830,11 @@ static void *t_hash_start(struct seq_file *m, loff_t *pos)
830 830
831static int t_hash_show(struct seq_file *m, void *v) 831static int t_hash_show(struct seq_file *m, void *v)
832{ 832{
833 struct ftrace_func_hook *rec; 833 struct ftrace_func_probe *rec;
834 struct hlist_node *hnd = v; 834 struct hlist_node *hnd = v;
835 char str[KSYM_SYMBOL_LEN]; 835 char str[KSYM_SYMBOL_LEN];
836 836
837 rec = hlist_entry(hnd, struct ftrace_func_hook, node); 837 rec = hlist_entry(hnd, struct ftrace_func_probe, node);
838 838
839 if (rec->ops->print) 839 if (rec->ops->print)
840 return rec->ops->print(m, rec->ip, rec->ops, rec->data); 840 return rec->ops->print(m, rec->ip, rec->ops, rec->data);
@@ -1208,14 +1208,15 @@ ftrace_match_record(struct dyn_ftrace *rec, char *regex, int len, int type)
1208 1208
1209static void ftrace_match_records(char *buff, int len, int enable) 1209static void ftrace_match_records(char *buff, int len, int enable)
1210{ 1210{
1211 char *search; 1211 unsigned int search_len;
1212 struct ftrace_page *pg; 1212 struct ftrace_page *pg;
1213 struct dyn_ftrace *rec; 1213 struct dyn_ftrace *rec;
1214 unsigned long flag;
1215 char *search;
1214 int type; 1216 int type;
1215 unsigned long flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
1216 unsigned search_len;
1217 int not; 1217 int not;
1218 1218
1219 flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
1219 type = ftrace_setup_glob(buff, len, &search, &not); 1220 type = ftrace_setup_glob(buff, len, &search, &not);
1220 1221
1221 search_len = strlen(search); 1222 search_len = strlen(search);
@@ -1263,14 +1264,16 @@ ftrace_match_module_record(struct dyn_ftrace *rec, char *mod,
1263 1264
1264static void ftrace_match_module_records(char *buff, char *mod, int enable) 1265static void ftrace_match_module_records(char *buff, char *mod, int enable)
1265{ 1266{
1266 char *search = buff; 1267 unsigned search_len = 0;
1267 struct ftrace_page *pg; 1268 struct ftrace_page *pg;
1268 struct dyn_ftrace *rec; 1269 struct dyn_ftrace *rec;
1269 int type = MATCH_FULL; 1270 int type = MATCH_FULL;
1270 unsigned long flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; 1271 char *search = buff;
1271 unsigned search_len = 0; 1272 unsigned long flag;
1272 int not = 0; 1273 int not = 0;
1273 1274
1275 flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
1276
1274 /* blank or '*' mean the same */ 1277 /* blank or '*' mean the same */
1275 if (strcmp(buff, "*") == 0) 1278 if (strcmp(buff, "*") == 0)
1276 buff[0] = 0; 1279 buff[0] = 0;
@@ -1348,9 +1351,9 @@ static int __init ftrace_mod_cmd_init(void)
1348device_initcall(ftrace_mod_cmd_init); 1351device_initcall(ftrace_mod_cmd_init);
1349 1352
1350static void 1353static void
1351function_trace_hook_call(unsigned long ip, unsigned long parent_ip) 1354function_trace_probe_call(unsigned long ip, unsigned long parent_ip)
1352{ 1355{
1353 struct ftrace_func_hook *entry; 1356 struct ftrace_func_probe *entry;
1354 struct hlist_head *hhd; 1357 struct hlist_head *hhd;
1355 struct hlist_node *n; 1358 struct hlist_node *n;
1356 unsigned long key; 1359 unsigned long key;
@@ -1376,18 +1379,18 @@ function_trace_hook_call(unsigned long ip, unsigned long parent_ip)
1376 ftrace_preempt_enable(resched); 1379 ftrace_preempt_enable(resched);
1377} 1380}
1378 1381
1379static struct ftrace_ops trace_hook_ops __read_mostly = 1382static struct ftrace_ops trace_probe_ops __read_mostly =
1380{ 1383{
1381 .func = function_trace_hook_call, 1384 .func = function_trace_probe_call,
1382}; 1385};
1383 1386
1384static int ftrace_hook_registered; 1387static int ftrace_probe_registered;
1385 1388
1386static void __enable_ftrace_function_hook(void) 1389static void __enable_ftrace_function_probe(void)
1387{ 1390{
1388 int i; 1391 int i;
1389 1392
1390 if (ftrace_hook_registered) 1393 if (ftrace_probe_registered)
1391 return; 1394 return;
1392 1395
1393 for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { 1396 for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) {
@@ -1399,16 +1402,16 @@ static void __enable_ftrace_function_hook(void)
1399 if (i == FTRACE_FUNC_HASHSIZE) 1402 if (i == FTRACE_FUNC_HASHSIZE)
1400 return; 1403 return;
1401 1404
1402 __register_ftrace_function(&trace_hook_ops); 1405 __register_ftrace_function(&trace_probe_ops);
1403 ftrace_startup(0); 1406 ftrace_startup(0);
1404 ftrace_hook_registered = 1; 1407 ftrace_probe_registered = 1;
1405} 1408}
1406 1409
1407static void __disable_ftrace_function_hook(void) 1410static void __disable_ftrace_function_probe(void)
1408{ 1411{
1409 int i; 1412 int i;
1410 1413
1411 if (!ftrace_hook_registered) 1414 if (!ftrace_probe_registered)
1412 return; 1415 return;
1413 1416
1414 for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { 1417 for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) {
@@ -1418,16 +1421,16 @@ static void __disable_ftrace_function_hook(void)
1418 } 1421 }
1419 1422
1420 /* no more funcs left */ 1423 /* no more funcs left */
1421 __unregister_ftrace_function(&trace_hook_ops); 1424 __unregister_ftrace_function(&trace_probe_ops);
1422 ftrace_shutdown(0); 1425 ftrace_shutdown(0);
1423 ftrace_hook_registered = 0; 1426 ftrace_probe_registered = 0;
1424} 1427}
1425 1428
1426 1429
1427static void ftrace_free_entry_rcu(struct rcu_head *rhp) 1430static void ftrace_free_entry_rcu(struct rcu_head *rhp)
1428{ 1431{
1429 struct ftrace_func_hook *entry = 1432 struct ftrace_func_probe *entry =
1430 container_of(rhp, struct ftrace_func_hook, rcu); 1433 container_of(rhp, struct ftrace_func_probe, rcu);
1431 1434
1432 if (entry->ops->free) 1435 if (entry->ops->free)
1433 entry->ops->free(&entry->data); 1436 entry->ops->free(&entry->data);
@@ -1436,21 +1439,21 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
1436 1439
1437 1440
1438int 1441int
1439register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops, 1442register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
1440 void *data) 1443 void *data)
1441{ 1444{
1442 struct ftrace_func_hook *entry; 1445 struct ftrace_func_probe *entry;
1443 struct ftrace_page *pg; 1446 struct ftrace_page *pg;
1444 struct dyn_ftrace *rec; 1447 struct dyn_ftrace *rec;
1445 unsigned long key;
1446 int type, len, not; 1448 int type, len, not;
1449 unsigned long key;
1447 int count = 0; 1450 int count = 0;
1448 char *search; 1451 char *search;
1449 1452
1450 type = ftrace_setup_glob(glob, strlen(glob), &search, &not); 1453 type = ftrace_setup_glob(glob, strlen(glob), &search, &not);
1451 len = strlen(search); 1454 len = strlen(search);
1452 1455
1453 /* we do not support '!' for function hooks */ 1456 /* we do not support '!' for function probes */
1454 if (WARN_ON(not)) 1457 if (WARN_ON(not))
1455 return -EINVAL; 1458 return -EINVAL;
1456 1459
@@ -1465,7 +1468,7 @@ register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
1465 1468
1466 entry = kmalloc(sizeof(*entry), GFP_KERNEL); 1469 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1467 if (!entry) { 1470 if (!entry) {
1468 /* If we did not hook to any, then return error */ 1471 /* If we did not process any, then return error */
1469 if (!count) 1472 if (!count)
1470 count = -ENOMEM; 1473 count = -ENOMEM;
1471 goto out_unlock; 1474 goto out_unlock;
@@ -1495,7 +1498,7 @@ register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
1495 hlist_add_head_rcu(&entry->node, &ftrace_func_hash[key]); 1498 hlist_add_head_rcu(&entry->node, &ftrace_func_hash[key]);
1496 1499
1497 } while_for_each_ftrace_rec(); 1500 } while_for_each_ftrace_rec();
1498 __enable_ftrace_function_hook(); 1501 __enable_ftrace_function_probe();
1499 1502
1500 out_unlock: 1503 out_unlock:
1501 mutex_unlock(&ftrace_lock); 1504 mutex_unlock(&ftrace_lock);
@@ -1504,15 +1507,15 @@ register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
1504} 1507}
1505 1508
1506enum { 1509enum {
1507 HOOK_TEST_FUNC = 1, 1510 PROBE_TEST_FUNC = 1,
1508 HOOK_TEST_DATA = 2 1511 PROBE_TEST_DATA = 2
1509}; 1512};
1510 1513
1511static void 1514static void
1512__unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops, 1515__unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
1513 void *data, int flags) 1516 void *data, int flags)
1514{ 1517{
1515 struct ftrace_func_hook *entry; 1518 struct ftrace_func_probe *entry;
1516 struct hlist_node *n, *tmp; 1519 struct hlist_node *n, *tmp;
1517 char str[KSYM_SYMBOL_LEN]; 1520 char str[KSYM_SYMBOL_LEN];
1518 int type = MATCH_FULL; 1521 int type = MATCH_FULL;
@@ -1527,7 +1530,7 @@ __unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
1527 type = ftrace_setup_glob(glob, strlen(glob), &search, &not); 1530 type = ftrace_setup_glob(glob, strlen(glob), &search, &not);
1528 len = strlen(search); 1531 len = strlen(search);
1529 1532
1530 /* we do not support '!' for function hooks */ 1533 /* we do not support '!' for function probes */
1531 if (WARN_ON(not)) 1534 if (WARN_ON(not))
1532 return; 1535 return;
1533 } 1536 }
@@ -1539,10 +1542,10 @@ __unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
1539 hlist_for_each_entry_safe(entry, n, tmp, hhd, node) { 1542 hlist_for_each_entry_safe(entry, n, tmp, hhd, node) {
1540 1543
1541 /* break up if statements for readability */ 1544 /* break up if statements for readability */
1542 if ((flags & HOOK_TEST_FUNC) && entry->ops != ops) 1545 if ((flags & PROBE_TEST_FUNC) && entry->ops != ops)
1543 continue; 1546 continue;
1544 1547
1545 if ((flags & HOOK_TEST_DATA) && entry->data != data) 1548 if ((flags & PROBE_TEST_DATA) && entry->data != data)
1546 continue; 1549 continue;
1547 1550
1548 /* do this last, since it is the most expensive */ 1551 /* do this last, since it is the most expensive */
@@ -1557,27 +1560,27 @@ __unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
1557 call_rcu(&entry->rcu, ftrace_free_entry_rcu); 1560 call_rcu(&entry->rcu, ftrace_free_entry_rcu);
1558 } 1561 }
1559 } 1562 }
1560 __disable_ftrace_function_hook(); 1563 __disable_ftrace_function_probe();
1561 mutex_unlock(&ftrace_lock); 1564 mutex_unlock(&ftrace_lock);
1562} 1565}
1563 1566
1564void 1567void
1565unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops, 1568unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
1566 void *data) 1569 void *data)
1567{ 1570{
1568 __unregister_ftrace_function_hook(glob, ops, data, 1571 __unregister_ftrace_function_probe(glob, ops, data,
1569 HOOK_TEST_FUNC | HOOK_TEST_DATA); 1572 PROBE_TEST_FUNC | PROBE_TEST_DATA);
1570} 1573}
1571 1574
1572void 1575void
1573unregister_ftrace_function_hook_func(char *glob, struct ftrace_hook_ops *ops) 1576unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
1574{ 1577{
1575 __unregister_ftrace_function_hook(glob, ops, NULL, HOOK_TEST_FUNC); 1578 __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC);
1576} 1579}
1577 1580
1578void unregister_ftrace_function_hook_all(char *glob) 1581void unregister_ftrace_function_probe_all(char *glob)
1579{ 1582{
1580 __unregister_ftrace_function_hook(glob, NULL, NULL, 0); 1583 __unregister_ftrace_function_probe(glob, NULL, NULL, 0);
1581} 1584}
1582 1585
1583static LIST_HEAD(ftrace_commands); 1586static LIST_HEAD(ftrace_commands);
@@ -1623,8 +1626,8 @@ int unregister_ftrace_command(struct ftrace_func_command *cmd)
1623 1626
1624static int ftrace_process_regex(char *buff, int len, int enable) 1627static int ftrace_process_regex(char *buff, int len, int enable)
1625{ 1628{
1626 struct ftrace_func_command *p;
1627 char *func, *command, *next = buff; 1629 char *func, *command, *next = buff;
1630 struct ftrace_func_command *p;
1628 int ret = -EINVAL; 1631 int ret = -EINVAL;
1629 1632
1630 func = strsep(&next, ":"); 1633 func = strsep(&next, ":");
@@ -2392,7 +2395,6 @@ static __init int ftrace_init_debugfs(void)
2392 "'set_ftrace_pid' entry\n"); 2395 "'set_ftrace_pid' entry\n");
2393 return 0; 2396 return 0;
2394} 2397}
2395
2396fs_initcall(ftrace_init_debugfs); 2398fs_initcall(ftrace_init_debugfs);
2397 2399
2398/** 2400/**