perf machine: Search for modules in %s/lib/modules/%s
PATCH 1/1 perf machine: Search for modules in %s/lib/modules/%s
Modules installed outside of the kernel's build system should go into "%s/lib/modules/%s/extra", but at present, perf will only look at them when they are in "%s/lib/modules/%s/kernel". Lets encourage good citizenship by relaxing this requirement to "%s/lib/modules/%s". This way open source modules that are out-of-tree have no incentive to start populating a directory reserved for in-kernel modules and I can stop hex-editing my system's perf binary when profiling OSS out-of-tree modules.
Feedback from Namhyung Kim correctly revealed that the hex-edits that I had been doing meant that perf was also traversing the build and source symlinks in %s/lib/modules/%s. That is undesireable, so we explicitly exclude them from traversal with a minor tweak to the traversal routine.
--- tools/perf/util/machine.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
tools/perf/util/machine.c +12 -4
@@ -717,7 +717,7 @@ static char *get_kernel_version(const char *root_dir) }static int map_groups__set_modules_path_dir (struct map_groups *mg, -const char *dir_name) +const char *dir_name,int depth) {struct dirent *dent;DIR *dir =opendir (dir_name);
@@ -742,7 +742,15 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, !strcmp(dent->d_name, ".."))continue ; - ret =map_groups__set_modules_path_dir (mg, path); +/* Do not follow top-level source and build symlinks */ +if (depth ==0 ) { +if (!strcmp (dent->d_name,"source" ) || + !strcmp (dent->d_name,"build" )) +continue ; + } + + ret =map_groups__set_modules_path_dir (mg, path, + depth +1 );if (ret <0 ) goto out; }else {
@@ -786,11 +794,11 @@ static int machine__set_modules_path(struct machine *machine)if (!version)return -1 ; -snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s/kernel" , +snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s" , machine->root_dir, version);free (version); -return map_groups__set_modules_path_dir (&machine->kmaps, modules_path); +return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); }static int machine__create_module (void *arg,const char *name,u64 start)
Signature · 1 line
1.8.3.2
Quoted 9 lines · Richard Yao
Modules installed outside of the kernel's build system should go into "%s/lib/modules/%s/extra", but at present, perf will only look at them when they are in "%s/lib/modules/%s/kernel". Lets encourage good citizenship by relaxing this requirement to "%s/lib/modules/%s". This way open source modules that are out-of-tree have no incentive to start populating a directory reserved for in-kernel modules and I can stop hex-editing my system's perf binary when profiling OSS out-of-tree modules.
Quoted 4 lines
Feedback from Namhyung Kim correctly revealed that the hex-edits that I had been doing meant that perf was also traversing the build and source symlinks in %s/lib/modules/%s. That is undesireable, so we explicitly exclude them from traversal with a minor tweak to the traversal routine.
looks good to me, Namhyung?
thanks,
jirka
Quoted 53 lines
Signed-off-by Richard Yao <[email protected]>--- tools/perf/util/machine.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)tools/perf/util/machine.c +12
-4@@ -717,7 +717,7 @@ static char *get_kernel_version(const char *root_dir) }static int map_groups__set_modules_path_dir (struct map_groups *mg, -const char *dir_name) +const char *dir_name,int depth) {struct dirent *dent;DIR *dir =opendir (dir_name);@@ -742,7 +742,15 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, !strcmp(dent->d_name, ".."))continue ; - ret =map_groups__set_modules_path_dir (mg, path); +/* Do not follow top-level source and build symlinks */ +if (depth ==0 ) { +if (!strcmp (dent->d_name,"source" ) || + !strcmp (dent->d_name,"build" )) +continue ; + } + + ret =map_groups__set_modules_path_dir (mg, path, + depth +1 );if (ret <0 ) goto out; }else {@@ -786,11 +794,11 @@ static int machine__set_modules_path(struct machine *machine)if (!version)return -1 ; -snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s/kernel" , +snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s" , machine->root_dir, version);free (version); -return map_groups__set_modules_path_dir (&machine->kmaps, modules_path); +return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); }static int machine__create_module (void *arg,const char *name,u64 start)Signature · 1 line
1.8.3.2
Quoted 10 lines · Jiri Olsa
Quoted 9 lines · Richard Yao
Modules installed outside of the kernel's build system should go into "%s/lib/modules/%s/extra", but at present, perf will only look at them when they are in "%s/lib/modules/%s/kernel". Lets encourage good citizenship by relaxing this requirement to "%s/lib/modules/%s". This way open source modules that are out-of-tree have no incentive to start populating a directory reserved for in-kernel modules and I can stop hex-editing my system's perf binary when profiling OSS out-of-tree modules.
Quoted 6 lines
Quoted 4 lines
Feedback from Namhyung Kim correctly revealed that the hex-edits that I had been doing meant that perf was also traversing the build and source symlinks in %s/lib/modules/%s. That is undesireable, so we explicitly exclude them from traversal with a minor tweak to the traversal routine.
looks good to me, Namhyung?
just realized Namhyung wasn't CC-ed on this one ;-)
jirka
Quoted 62 lines
thanks,
jirkaQuoted 53 lines
Signed-off-by Richard Yao <[email protected]>--- tools/perf/util/machine.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)tools/perf/util/machine.c +12
-4@@ -717,7 +717,7 @@ static char *get_kernel_version(const char *root_dir) }static int map_groups__set_modules_path_dir (struct map_groups *mg, -const char *dir_name) +const char *dir_name,int depth) {struct dirent *dent;DIR *dir =opendir (dir_name);@@ -742,7 +742,15 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, !strcmp(dent->d_name, ".."))continue ; - ret =map_groups__set_modules_path_dir (mg, path); +/* Do not follow top-level source and build symlinks */ +if (depth ==0 ) { +if (!strcmp (dent->d_name,"source" ) || + !strcmp (dent->d_name,"build" )) +continue ; + } + + ret =map_groups__set_modules_path_dir (mg, path, + depth +1 );if (ret <0 ) goto out; }else {@@ -786,11 +794,11 @@ static int machine__set_modules_path(struct machine *machine)if (!version)return -1 ; -snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s/kernel" , +snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s" , machine->root_dir, version);free (version); -return map_groups__set_modules_path_dir (&machine->kmaps, modules_path); +return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); }static int machine__create_module (void *arg,const char *name,u64 start)Signature · 1 line
1.8.3.2--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Hi Jiri,
Quoted 11 lines · Jiri Olsa
Quoted 10 lines · Jiri Olsa
Quoted 9 lines · Richard Yao
Modules installed outside of the kernel's build system should go into "%s/lib/modules/%s/extra", but at present, perf will only look at them when they are in "%s/lib/modules/%s/kernel". Lets encourage good citizenship by relaxing this requirement to "%s/lib/modules/%s". This way open source modules that are out-of-tree have no incentive to start populating a directory reserved for in-kernel modules and I can stop hex-editing my system's perf binary when profiling OSS out-of-tree modules.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Feedback from Namhyung Kim correctly revealed that the hex-edits that I had been doing meant that perf was also traversing the build and source symlinks in %s/lib/modules/%s. That is undesireable, so we explicitly exclude them from traversal with a minor tweak to the traversal routine.
looks good to me, Namhyung?
just realized Namhyung wasn't CC-ed on this one ;-)
:)
Well, I still prefer the symlink check with lstat(), I can live with this, so:
Thanks,
Namhyung
Quoted 63 lines
Quoted 63 lines
thanks,
jirkaQuoted 53 lines
Signed-off-by Richard Yao <[email protected]>--- tools/perf/util/machine.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)tools/perf/util/machine.c +12
-4@@ -717,7 +717,7 @@ static char *get_kernel_version(const char *root_dir) }static int map_groups__set_modules_path_dir (struct map_groups *mg, -const char *dir_name) +const char *dir_name,int depth) {struct dirent *dent;DIR *dir =opendir (dir_name);@@ -742,7 +742,15 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, !strcmp(dent->d_name, ".."))continue ; - ret =map_groups__set_modules_path_dir (mg, path); +/* Do not follow top-level source and build symlinks */ +if (depth ==0 ) { +if (!strcmp (dent->d_name,"source" ) || + !strcmp (dent->d_name,"build" )) +continue ; + } + + ret =map_groups__set_modules_path_dir (mg, path, + depth +1 );if (ret <0 ) goto out; }else {@@ -786,11 +794,11 @@ static int machine__set_modules_path(struct machine *machine)if (!version)return -1 ; -snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s/kernel" , +snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s" , machine->root_dir, version);free (version); -return map_groups__set_modules_path_dir (&machine->kmaps, modules_path); +return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); }static int machine__create_module (void *arg,const char *name,u64 start)Signature · 1 line
1.8.3.2--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
tip-bot for Richard Yao
merge bot[tip:perf/core] perf machine: Search for modules in %s/lib/ modules/%s
In reply to Richard Yaoperf machine: Search for modules in %s/lib/modules/%s
Commit-ID: 61d4290cc1f10588147b76b385875f06827d47ff Gitweb: http://git.kernel.org/tip/61d4290cc1f10588147b76b385875f06827d47ff Author: Richard Yao <[email protected]> AuthorDate: Sat, 26 Apr 2014 13:17:55 -0400 Committer: Jiri Olsa <[email protected]> CommitDate: Wed, 30 Apr 2014 16:49:29 +0200
perf machine: Search for modules in %s/lib/modules/%s
Modules installed outside of the kernel's build system should go into "%s/lib/modules/%s/extra", but at present, perf will only look at them when they are in "%s/lib/modules/%s/kernel". Lets encourage good citizenship by relaxing this requirement to "%s/lib/modules/%s". This way open source modules that are out-of-tree have no incentive to start populating a directory reserved for in-kernel modules and I can stop hex-editing my system's perf binary when profiling OSS out-of-tree modules.
Feedback from Namhyung Kim correctly revealed that the hex-edits that I had been doing meant that perf was also traversing the build and source symlinks in %s/lib/modules/%s. That is undesireable, so we explicitly exclude them from traversal with a minor tweak to the traversal routine.
--- tools/perf/util/machine.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
tools/perf/util/machine.c +12 -4
@@ -717,7 +717,7 @@ static char *get_kernel_version(const char *root_dir) }static int map_groups__set_modules_path_dir (struct map_groups *mg, -const char *dir_name) +const char *dir_name,int depth) {struct dirent *dent;DIR *dir =opendir (dir_name);
@@ -742,7 +742,15 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, !strcmp(dent->d_name, ".."))continue ; - ret =map_groups__set_modules_path_dir (mg, path); +/* Do not follow top-level source and build symlinks */ +if (depth ==0 ) { +if (!strcmp (dent->d_name,"source" ) || + !strcmp (dent->d_name,"build" )) +continue ; + } + + ret =map_groups__set_modules_path_dir (mg, path, + depth +1 );if (ret <0 ) goto out; }else {
@@ -786,11 +794,11 @@ static int machine__set_modules_path(struct machine *machine)if (!version)return -1 ; -snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s/kernel" , +snprintf (modules_path,sizeof (modules_path),"%s/lib/modules/%s" , machine->root_dir, version);free (version); -return map_groups__set_modules_path_dir (&machine->kmaps, modules_path); +return map_groups__set_modules_path_dir (&machine->kmaps, modules_path,0 ); }static int machine__create_module (void *arg,const char *name,u64 start)