public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Taeung Song <treeze.taeung@gmail.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v3 1/4] perf config: Introduce perf_config_set class
Date: Thu, 24 Mar 2016 15:46:00 +0900	[thread overview]
Message-ID: <56F38D28.3000504@gmail.com> (raw)
In-Reply-To: <20160324060734.GA32072@sejong>

Hi, Namhyung

On 03/24/2016 03:07 PM, Namhyung Kim wrote:
> Hi Taeung,
>
> On Thu, Mar 24, 2016 at 05:16:30AM +0900, Taeung Song wrote:
>> This infrastructure code was designed for
>> upcoming features of perf-config.
>>
>> That collect config key-value pairs from user and
>> system config files (i.e. user wide ~/.perfconfig
>> and system wide $(sysconfdir)/perfconfig)
>> to manage perf's configs.
>>
>> Cc: Jiri Olsa <jolsa@kernel.org>
>> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
>
> Acked-by: Namhyung Kim <namhyung@kernel.org>
>

Thank you!!

But I'm so sorry for my mistake.
I missed perf_config_set__delete() out when the error occur in 
collect_config().

(If returning -1 from collect_config(), perf process die with some error 
message at once
so it is needed to call perf_config_set__delete() before that moment)

So, I'll resend this patch after fixing it as below.

diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 725015f..3831733 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -705,14 +706,15 @@ static int set_value(struct perf_config_item 
*config_item, const char *value)
  }

  static int collect_config(const char *var, const char *value,
-                          void *section_list)
+                          void *perf_config_set)
  {
          int ret = -1;
          char *ptr, *key;
          char *section_name, *name;
          struct perf_config_section *section = NULL;
          struct perf_config_item *config_item = NULL;
-        struct list_head *sections = section_list;
+        struct perf_config_set *perf_configs = perf_config_set;
+        struct list_head *sections = &perf_configs->sections;

          key = ptr = strdup(var);
          if (!key) {
@@ -743,7 +745,8 @@ static int collect_config(const char *var, const 
char *value,

  out_free:
          free(key);
-        return ret;
+        perf_config_set__delete(perf_configs);
+        return -1;
  }

  static struct perf_config_set *perf_config_set__init(struct 
perf_config_set *perf_configs)
@@ -777,7 +780,7 @@ struct perf_config_set *perf_config_set__new(void)
                  return NULL;

          perf_config_set__init(perf_configs);
-        perf_config(collect_config, &perf_configs->sections);
+        perf_config(collect_config, perf_configs);

          return perf_configs;
  }


Thanks,
Taeung

>
>
>> ---
>>   tools/perf/util/config.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++
>>   tools/perf/util/config.h |  26 ++++++++
>>   2 files changed, 195 insertions(+)
>>   create mode 100644 tools/perf/util/config.h
>>
>> diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
>> index 4e72763..3beeceb 100644
>> --- a/tools/perf/util/config.c
>> +++ b/tools/perf/util/config.c
>> @@ -13,6 +13,7 @@
>>   #include <subcmd/exec-cmd.h>
>>   #include "util/hist.h"  /* perf_hist_config */
>>   #include "util/llvm-utils.h"   /* perf_llvm_config */
>> +#include "config.h"
>>
>>   #define MAXNAME (256)
>>
>> @@ -506,6 +507,174 @@ out:
>>   	return ret;
>>   }
>>
>> +static struct perf_config_section *find_section(struct list_head *sections,
>> +						const char *section_name)
>> +{
>> +	struct perf_config_section *section;
>> +
>> +	list_for_each_entry(section, sections, list)
>> +		if (!strcmp(section->name, section_name))
>> +			return section;
>> +
>> +	return NULL;
>> +}
>> +
>> +static struct perf_config_item *find_config_item(const char *name,
>> +						 struct perf_config_section *section)
>> +{
>> +	struct perf_config_item *config_item;
>> +
>> +	list_for_each_entry(config_item, &section->config_items, list)
>> +		if (!strcmp(config_item->name, name))
>> +			return config_item;
>> +
>> +	return NULL;
>> +}
>> +
>> +static void find_config(struct list_head *sections,
>> +			struct perf_config_section **section,
>> +			struct perf_config_item **config_item,
>> +			const char *section_name, const char *name)
>> +{
>> +	*section = find_section(sections, section_name);
>> +
>> +	if (*section != NULL)
>> +		*config_item = find_config_item(name, *section);
>> +	else
>> +		*config_item = NULL;
>> +}
>> +
>> +static struct perf_config_section *add_section(struct list_head *sections,
>> +					       const char *section_name)
>> +{
>> +	struct perf_config_section *section = zalloc(sizeof(*section));
>> +
>> +	if (!section)
>> +		return NULL;
>> +
>> +	INIT_LIST_HEAD(&section->config_items);
>> +	section->name = strdup(section_name);
>> +	if (!section->name) {
>> +		pr_err("%s: strdup failed\n", __func__);
>> +		free(section);
>> +		return NULL;
>> +	}
>> +
>> +	list_add_tail(&section->list, sections);
>> +	return section;
>> +}
>> +
>> +static struct perf_config_item *add_config_item(struct perf_config_section *section,
>> +						const char *name)
>> +{
>> +	struct perf_config_item *config_item = zalloc(sizeof(*config_item));
>> +
>> +	if (!config_item)
>> +		return NULL;
>> +
>> +	config_item->name = strdup(name);
>> +	if (!name) {
>> +		pr_err("%s: strdup failed\n", __func__);
>> +		goto out_err;
>> +	}
>> +
>> +	list_add_tail(&config_item->list, &section->config_items);
>> +	return config_item;
>> +
>> +out_err:
>> +	free(config_item);
>> +	return NULL;
>> +}
>> +
>> +static int set_value(struct perf_config_item *config_item, const char *value)
>> +{
>> +	char *val = strdup(value);
>> +
>> +	if (!val)
>> +		return -1;
>> +
>> +	free(config_item->value);
>> +	config_item->value = val;
>> +	return 0;
>> +}
>> +
>> +static int collect_config(const char *var, const char *value,
>> +			  void *section_list)
>> +{
>> +	int ret = -1;
>> +	char *ptr, *key;
>> +	char *section_name, *name;
>> +	struct perf_config_section *section = NULL;
>> +	struct perf_config_item *config_item = NULL;
>> +	struct list_head *sections = section_list;
>> +
>> +	key = ptr = strdup(var);
>> +	if (!key) {
>> +		pr_err("%s: strdup failed\n", __func__);
>> +		return -1;
>> +	}
>> +
>> +	section_name = strsep(&ptr, ".");
>> +	name = ptr;
>> +	if (name == NULL || value == NULL)
>> +		goto out_free;
>> +
>> +	find_config(sections, &section, &config_item, section_name, name);
>> +
>> +	if (!section) {
>> +		section = add_section(sections, section_name);
>> +		if (!section)
>> +			goto out_free;
>> +	}
>> +	if (!config_item) {
>> +		config_item = add_config_item(section, name);
>> +		if (!config_item)
>> +			goto out_free;
>> +	}
>> +
>> +	ret = set_value(config_item, value);
>> +	return ret;
>> +
>> +out_free:
>> +	free(key);
>> +	return ret;
>> +}
>> +
>> +struct perf_config_set *perf_config_set__new(void)
>> +{
>> +	struct perf_config_set *perf_configs = zalloc(sizeof(*perf_configs));
>> +
>> +	if (!perf_configs)
>> +		return NULL;
>> +
>> +	INIT_LIST_HEAD(&perf_configs->sections);
>> +	perf_config(collect_config, &perf_configs->sections);
>> +
>> +	return perf_configs;
>> +}
>> +
>> +void perf_config_set__delete(struct perf_config_set *perf_configs)
>> +{
>> +	struct perf_config_section *section, *section_tmp;
>> +	struct perf_config_item *config_item, *item_tmp;
>> +
>> +	list_for_each_entry_safe(section, section_tmp,
>> +				 &perf_configs->sections, list) {
>> +		list_for_each_entry_safe(config_item, item_tmp,
>> +					 &section->config_items, list) {
>> +			list_del(&config_item->list);
>> +			free(config_item->name);
>> +			free(config_item->value);
>> +			free(config_item);
>> +		}
>> +		list_del(&section->list);
>> +		free(section->name);
>> +		free(section);
>> +	}
>> +
>> +	free(perf_configs);
>> +}
>> +
>>   /*
>>    * Call this to report error for your variable that should not
>>    * get a boolean value (i.e. "[my] var" means "true").
>> diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
>> new file mode 100644
>> index 0000000..e270e51
>> --- /dev/null
>> +++ b/tools/perf/util/config.h
>> @@ -0,0 +1,26 @@
>> +#ifndef __PERF_CONFIG_H
>> +#define __PERF_CONFIG_H
>> +
>> +#include <stdbool.h>
>> +#include <linux/list.h>
>> +
>> +struct perf_config_item {
>> +	char *name;
>> +	char *value;
>> +	struct list_head list;
>> +};
>> +
>> +struct perf_config_section {
>> +	char *name;
>> +	struct list_head config_items;
>> +	struct list_head list;
>> +};
>> +
>> +struct perf_config_set {
>> +	struct list_head sections;
>> +};
>> +
>> +struct perf_config_set *perf_config_set__new(void);
>> +void perf_config_set__delete(struct perf_config_set *perf_configs);
>> +
>> +#endif /* __PERF_CONFIG_H */
>> --
>> 2.5.0
>>

  reply	other threads:[~2016-03-24  6:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 20:16 [RFC][PATCH v3 0/4] perf config: Infrastructure code for perf-config Taeung Song
2016-03-23 20:16 ` [PATCH v3 1/4] perf config: Introduce perf_config_set class Taeung Song
2016-03-24  6:07   ` Namhyung Kim
2016-03-24  6:46     ` Taeung Song [this message]
2016-03-28 21:06       ` Arnaldo Carvalho de Melo
2016-03-29  0:18         ` Taeung Song
2016-03-23 20:16 ` [PATCH v3 2/4] perf config: Let show_config() work with perf_config_set Taeung Song
2016-03-24  6:08   ` Namhyung Kim
2016-03-23 20:16 ` [PATCH v3 3/4] perf config: Prepare all default configs Taeung Song
2016-03-24  6:08   ` Namhyung Kim
2016-03-23 20:16 ` [PATCH v3 4/4] perf config: Initialize perf_config_set with " Taeung Song
2016-03-24  6:13   ` Namhyung Kim
2016-03-24  6:49     ` Taeung Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56F38D28.3000504@gmail.com \
    --to=treeze.taeung@gmail.com \
    --cc=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox