Re: [PATCH v2 1/2] perf tools: Make find_vdso_map() more modular

From: Florian Fainelli
Date: Mon Dec 10 2018 - 15:16:53 EST


On 11/27/18 1:31 AM, Jiri Olsa wrote:
> On Thu, Oct 25, 2018 at 10:55:07AM -0700, Florian Fainelli wrote:
>> In preparation for checking that the vectors page on the ARM
>> architecture, refactor the find_vdso_map() function to accept finding an
>> arbitrary string and create a dedicated helper function for that under
>> util/find-map.c and update find_vdso_map() to use it.
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
>> ---
>> tools/perf/util/find-map.c | 31 +++++++++++++++++++++++++++++++
>> tools/perf/util/find-vdso-map.c | 30 +++---------------------------
>> 2 files changed, 34 insertions(+), 27 deletions(-)
>> create mode 100644 tools/perf/util/find-map.c
>>
>> diff --git a/tools/perf/util/find-map.c b/tools/perf/util/find-map.c
>> new file mode 100644
>> index 000000000000..19a3431a7b2a
>> --- /dev/null
>> +++ b/tools/perf/util/find-map.c
>> @@ -0,0 +1,31 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +static int find_map(void **start, void **end, const char *name)
>> +{
>> + FILE *maps;
>> + char line[128];
>> + int found = 0;
>> +
>> + maps = fopen("/proc/self/maps", "r");
>> + if (!maps) {
>> + fprintf(stderr, "vdso: cannot open maps\n");
>> + return -1;
>> + }
>> +
>> + while (!found && fgets(line, sizeof(line), maps)) {
>> + int m = -1;
>> +
>> + /* We care only about private r-x mappings. */
>> + if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
>> + start, end, &m))
>> + continue;
>> + if (m < 0)
>> + continue;
>> +
>> + if (!strncmp(&line[m], name, strlen(name)))
>> + found = 1;
>> + }
>> +
>> + fclose(maps);
>> + return !found;
>> +}
>
> please keep just one object for both.. looks to me like
> it coud go to util.c.. or just find-map.c if there's
> a reason to have this separated

The reason for keeping both implementations separate is because
VDSO__MAP_NAME may not be defined/applicable for all architectures, so
instead of having them have to define VDSO__MAP_NAME just to get that
file to build, they would only include find-map.c to get access to
find_map() and then search for specific tokens.

Would you prefer if find_map() was moved to tools/perf/util/util.c?
--
Florian