mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Platform Driver <platform-driver-x86@vger.kernel.org>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	Zhang Rui <rui.zhang@intel.com>,
	Rafael Wysocki <rafael.j.wysocki@intel.com>,
	Len Brown <len.brown@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Arjan van de Ven <arjan@linux.intel.com>
Subject: Re: [PATCH 1/1] Introduce Intel RAPL cooling device driver
Date: Tue, 02 Apr 2013 15:35:15 -0700	[thread overview]
Message-ID: <1364942115.2085.10.camel@joe-AO722> (raw)
In-Reply-To: <1364940936-20846-2-git-send-email-jacob.jun.pan@linux.intel.com>

On Tue, 2013-04-02 at 15:15 -0700, Jacob Pan wrote:
> RAPL(Running Average Power Limit) interface provides platform software
> with the ability to monitor, control, and get notifications on SOC
> power consumptions. Since its first appearance on Sandy Bridge, more
> features have being added to extend its usage. In RAPL, platforms are
> divided into domains for fine grained control. These domains include
> package, DRAM controller, CPU core (Power Plane 0), graphics uncore
> (power plane 1), etc.

trivia only:

> diff --git a/drivers/platform/x86/intel_rapl.c b/drivers/platform/x86/intel_rapl.c
[]
> +static char *rapl_domain_names[] = {
> +	"package",
> +	"power_plane_0",
> +	"power_plane_1",
> +	"dram",
> +};

const

> +static void rapl_init_domains(void)
> +{
> +	int i, j = 0;


I think this below is unpleasant to read.
Maybe add a temporary pointer and get rid of j?

	typeof rapl_domains *t = rapl_domains;

(not typeof, but the actual type)

> +
> +	for (i = 0; i < RAPL_DOMAIN_MAX; i++) {
> +		unsigned int mask = rg_data.domain_map & (1 << i);
> +
> +		switch (mask) {
> +		case 1 << RAPL_DOMAIN_PKG:
> +			rapl_domains[j].name =
> +				rapl_domain_names[RAPL_DOMAIN_PKG];

			t->name = rapl_domain_names[RAPL_DOMAIN_PKG];
			etc...
[]
> +		if (mask)
> +			j++;

			t++;

> +/* in the order of enum rapl_primitives */
> +static struct rapl_primitive_info rpi[] = {

const?

> +	/* name, mask, shift, msr index, unit divisor*/
> +	PRIMITIVE_INFO_INIT(energy, ENERGY_STATUS_MASK, 0,
> +			RAPL_DOMAIN_MSR_STATUS, ENERGY_UNIT,
> +			RAPL_PRIMITIVE_EVENT_CAP),

[]
> +static int rapl_read_data_raw(struct rapl_domain *domain,
> +			struct rapl_primitive_info *rp, bool xlate, u64 *data)
> +{
[]
> +	/* specical-case pkg lock bit since pkg domain uses a different bit */

special-case

[]
> +static ssize_t store_event_control(struct rapl_domain *rd, const char *buf,
> +				size_t size)
> +{
> +	unsigned int efd, cfd, new_threshold;
> +	struct file *efile = NULL;
> +	struct file *cfile = NULL;
> +	int ret = 0;
> +	int prim;
> +	struct rapl_event *ep;
> +	u64 val;
> +
> +	if (sscanf(buf, "%u %u %u", &efd, &cfd, &new_threshold) != 3)
> +		return -EINVAL;
> +
> +	efile = eventfd_fget(efd);
> +	if (IS_ERR(efile)) {
> +		ret = PTR_ERR(efile);
> +		pr_err("failed to get eventfd file %d\n", efd);
> +		goto done;
> +	}
> +	cfile = fget(cfd);
> +	if (!cfile) {
> +		ret = -EBADF;
> +		fput(efile);
> +		goto done;
> +	}
> +	/* check if the cfile belongs to the same rapl domain */
> +	if (strcmp(rd->kobj.sd->s_name,
> +			cfile->f_dentry->d_parent->d_name.name)) {
> +		pr_debug("cfile does not belong to domain %s\n",
> +			rd->kobj.sd->s_name);
> +		ret = -EINVAL;
> +		goto exit_cleanup_fds;
> +	}
> +	prim = primitive_name_to_entry(
> +		(const char *)cfile->f_dentry->d_name.name);
> +	if (prim < 0) {
> +		pr_err("failed lookup primitive id for control file %s\n",
> +			cfile->f_dentry->d_name.name);
> +		ret = -EINVAL;
> +		goto exit_cleanup_fds;
> +	}
> +	if (!(rpi[prim].flag & RAPL_PRIMITIVE_EVENT_CAP)) {
> +		pr_info("Invalid control file %d\n", prim);
> +		ret = -EINVAL;
> +		goto exit_cleanup_fds;
> +	}

Perhaps all these pr_<levels> should be pr_err as they
all lead to a failure path.


[]

> +static int stop_periodic_polling(void)
> +{
> +	if (true == polling_started) {

You don't need a comparison,
	if (polling_started) {
is perhaps better.

[]
> +static int rapl_detect_domains(void)
> +{
[]
> +	pr_info("Found %d vaild RAPL domains\n", rg_data.nr_domains);

valid

> +	rapl_domains = kzalloc(sizeof(struct rapl_domain) * rg_data.nr_domains,
> +			GFP_KERNEL);

kcalloc

> +	if (NULL == rapl_domains) {
> +		pr_err("Failed to allocate memory for rapl domain\n");

You don't need OOM messages as the memory
subsystem already does a dump_stack on OOM.

[]

> +static int __init intel_rapl_init(void)
> +{

> +	rd_data = kzalloc(sizeof(struct rapl_domain_data) * rg_data.nr_domains,
> +			GFP_KERNEL);

kcalloc again.

> +	if (NULL == rd_data) {
> +		pr_err("Failed to allocate memory for rapl domain data\n");

OOM too.



  parent reply	other threads:[~2013-04-02 22:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-02 22:15 [PATCH 0/1] RAPL (Running Average Power Limit) driver Jacob Pan
2013-04-02 22:15 ` [PATCH 1/1] Introduce Intel RAPL cooling device driver Jacob Pan
2013-04-02 21:42   ` Randy Dunlap
2013-04-02 21:47   ` Randy Dunlap
2013-04-02 23:04     ` Greg Kroah-Hartman
2013-04-02 22:35   ` Joe Perches [this message]
2013-04-02 23:00   ` Greg KH
2013-04-02 23:03     ` Greg KH
2013-04-02 23:33     ` Jacob Pan
2013-04-02 23:48       ` Greg KH
2013-04-03  0:17         ` Jacob Pan
2013-04-03 16:30           ` Greg KH
2013-04-03 18:03             ` Jacob Pan
2013-04-05 20:24               ` Greg KH
2013-04-02 23:53     ` Jacob Pan
2013-04-03  0:13       ` Greg KH
2013-04-03  4:48         ` Jacob Pan
2013-04-03 16:35           ` Greg KH
2013-04-03 17:35             ` Jacob Pan
2013-04-05 20:23               ` Greg KH
2013-04-05 21:33                 ` Jacob Pan
2013-04-05 21:46                   ` Greg KH
2013-04-03 10:24   ` Paul Bolle

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=1364942115.2085.10.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=arjan@linux.intel.com \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.garrett@nebula.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    /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

all inboxes | Powered by JetHome®