Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Add support for named triggers

Named triggers are sets of triggers that share a common set of trigger
data. An example of functionality that could benefit from this type
of capability would be a set of inlined probes that would each
contribute event counts, for example, to a shared counter data
structure.

The first named trigger registered with a given name owns the common
trigger data that the others subsequently registered with the same
name will reference. The functions defined here allow users to add,
delete, and find named triggers.

It also adds functions to pause and unpause named triggers; since
named triggers act upon common data, they should also be paused and
unpaused as a group.

Link: http://lkml.kernel.org/r/c09ff648360f65b10a3e321eddafe18060b4a04f.1457029949.git.tom.zanussi@linux.intel.com

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

authored by

Tom Zanussi and committed by
Steven Rostedt
db1388b4 52a7f16d

+156
+13
kernel/trace/trace.h
··· 1184 1184 char *filter_str; 1185 1185 void *private_data; 1186 1186 bool paused; 1187 + bool paused_tmp; 1187 1188 struct list_head list; 1189 + char *name; 1190 + struct list_head named_list; 1191 + struct event_trigger_data *named_data; 1188 1192 }; 1189 1193 1190 1194 /* Avoid typos */ ··· 1231 1227 extern int set_trigger_filter(char *filter_str, 1232 1228 struct event_trigger_data *trigger_data, 1233 1229 struct trace_event_file *file); 1230 + extern struct event_trigger_data *find_named_trigger(const char *name); 1231 + extern bool is_named_trigger(struct event_trigger_data *test); 1232 + extern int save_named_trigger(const char *name, 1233 + struct event_trigger_data *data); 1234 + extern void del_named_trigger(struct event_trigger_data *data); 1235 + extern void pause_named_trigger(struct event_trigger_data *data); 1236 + extern void unpause_named_trigger(struct event_trigger_data *data); 1237 + extern void set_named_trigger_data(struct event_trigger_data *data, 1238 + struct event_trigger_data *named_data); 1234 1239 extern int register_event_command(struct event_command *cmd); 1235 1240 extern int unregister_event_command(struct event_command *cmd); 1236 1241 extern int register_trigger_hist_enable_disable_cmds(void);
+143
kernel/trace/trace_events_trigger.c
··· 641 641 trigger_data->ops = trigger_ops; 642 642 trigger_data->cmd_ops = cmd_ops; 643 643 INIT_LIST_HEAD(&trigger_data->list); 644 + INIT_LIST_HEAD(&trigger_data->named_list); 644 645 645 646 if (glob[0] == '!') { 646 647 cmd_ops->unreg(glob+1, trigger_ops, trigger_data, file); ··· 763 762 } 764 763 out: 765 764 return ret; 765 + } 766 + 767 + static LIST_HEAD(named_triggers); 768 + 769 + /** 770 + * find_named_trigger - Find the common named trigger associated with @name 771 + * @name: The name of the set of named triggers to find the common data for 772 + * 773 + * Named triggers are sets of triggers that share a common set of 774 + * trigger data. The first named trigger registered with a given name 775 + * owns the common trigger data that the others subsequently 776 + * registered with the same name will reference. This function 777 + * returns the common trigger data associated with that first 778 + * registered instance. 779 + * 780 + * Return: the common trigger data for the given named trigger on 781 + * success, NULL otherwise. 782 + */ 783 + struct event_trigger_data *find_named_trigger(const char *name) 784 + { 785 + struct event_trigger_data *data; 786 + 787 + if (!name) 788 + return NULL; 789 + 790 + list_for_each_entry(data, &named_triggers, named_list) { 791 + if (data->named_data) 792 + continue; 793 + if (strcmp(data->name, name) == 0) 794 + return data; 795 + } 796 + 797 + return NULL; 798 + } 799 + 800 + /** 801 + * is_named_trigger - determine if a given trigger is a named trigger 802 + * @test: The trigger data to test 803 + * 804 + * Return: true if 'test' is a named trigger, false otherwise. 805 + */ 806 + bool is_named_trigger(struct event_trigger_data *test) 807 + { 808 + struct event_trigger_data *data; 809 + 810 + list_for_each_entry(data, &named_triggers, named_list) { 811 + if (test == data) 812 + return true; 813 + } 814 + 815 + return false; 816 + } 817 + 818 + /** 819 + * save_named_trigger - save the trigger in the named trigger list 820 + * @name: The name of the named trigger set 821 + * @data: The trigger data to save 822 + * 823 + * Return: 0 if successful, negative error otherwise. 824 + */ 825 + int save_named_trigger(const char *name, struct event_trigger_data *data) 826 + { 827 + data->name = kstrdup(name, GFP_KERNEL); 828 + if (!data->name) 829 + return -ENOMEM; 830 + 831 + list_add(&data->named_list, &named_triggers); 832 + 833 + return 0; 834 + } 835 + 836 + /** 837 + * del_named_trigger - delete a trigger from the named trigger list 838 + * @data: The trigger data to delete 839 + */ 840 + void del_named_trigger(struct event_trigger_data *data) 841 + { 842 + kfree(data->name); 843 + data->name = NULL; 844 + 845 + list_del(&data->named_list); 846 + } 847 + 848 + static void __pause_named_trigger(struct event_trigger_data *data, bool pause) 849 + { 850 + struct event_trigger_data *test; 851 + 852 + list_for_each_entry(test, &named_triggers, named_list) { 853 + if (strcmp(test->name, data->name) == 0) { 854 + if (pause) { 855 + test->paused_tmp = test->paused; 856 + test->paused = true; 857 + } else { 858 + test->paused = test->paused_tmp; 859 + } 860 + } 861 + } 862 + } 863 + 864 + /** 865 + * pause_named_trigger - Pause all named triggers with the same name 866 + * @data: The trigger data of a named trigger to pause 867 + * 868 + * Pauses a named trigger along with all other triggers having the 869 + * same name. Because named triggers share a common set of data, 870 + * pausing only one is meaningless, so pausing one named trigger needs 871 + * to pause all triggers with the same name. 872 + */ 873 + void pause_named_trigger(struct event_trigger_data *data) 874 + { 875 + __pause_named_trigger(data, true); 876 + } 877 + 878 + /** 879 + * unpause_named_trigger - Un-pause all named triggers with the same name 880 + * @data: The trigger data of a named trigger to unpause 881 + * 882 + * Un-pauses a named trigger along with all other triggers having the 883 + * same name. Because named triggers share a common set of data, 884 + * unpausing only one is meaningless, so unpausing one named trigger 885 + * needs to unpause all triggers with the same name. 886 + */ 887 + void unpause_named_trigger(struct event_trigger_data *data) 888 + { 889 + __pause_named_trigger(data, false); 890 + } 891 + 892 + /** 893 + * set_named_trigger_data - Associate common named trigger data 894 + * @data: The trigger data of a named trigger to unpause 895 + * 896 + * Named triggers are sets of triggers that share a common set of 897 + * trigger data. The first named trigger registered with a given name 898 + * owns the common trigger data that the others subsequently 899 + * registered with the same name will reference. This function 900 + * associates the common trigger data from the first trigger with the 901 + * given trigger. 902 + */ 903 + void set_named_trigger_data(struct event_trigger_data *data, 904 + struct event_trigger_data *named_data) 905 + { 906 + data->named_data = named_data; 766 907 } 767 908 768 909 static void