From patchwork Fri Jun 7 21:53:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 17694 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f198.google.com (mail-gg0-f198.google.com [209.85.161.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7B5CF25E27 for ; Fri, 7 Jun 2013 21:53:18 +0000 (UTC) Received: by mail-gg0-f198.google.com with SMTP id p4sf1873075ggn.5 for ; Fri, 07 Jun 2013 14:53:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=AaGe3HoHMoex0KzTELH0WR1CBTl546hdtOJxDGFPO5s=; b=Ij+Ut4TNqEGhIRKGx29PZp/RBcBJ3Pw+aOaSKGNo78FZv5VebYHqfwaNyk5YE0Uzd1 f5GgR0VBuqAEcOAzooByQgqLFslnL/Bb6gADVCdjxnkFxC4elwkMliMlXdIddHfMxePm SXwPoodvzmL00uhNpN5V5m+ubyBa+6x6RP/DfAOg2i3JJby3r2VZUaJ5AZgxYztUglVI TI2LaBWIScK2t8hCkMIcRH4v0vlO7neMzn6JD94aai6Sopi5loD9px0J2tU5JT9zcIG0 8BAjyd+vWv2+jCZhDTZ0DuG0kwmX7ENpp4AYx4REbgsk+yEkRzYPBVj0bLZxEONGRTZz MqdA== X-Received: by 10.236.175.234 with SMTP id z70mr281401yhl.50.1370641998221; Fri, 07 Jun 2013 14:53:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.98.138 with SMTP id ei10ls1822216qeb.79.gmail; Fri, 07 Jun 2013 14:53:17 -0700 (PDT) X-Received: by 10.52.99.168 with SMTP id er8mr218279vdb.3.1370641997831; Fri, 07 Jun 2013 14:53:17 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id fb8si259386vcb.79.2013.06.07.14.53.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Jun 2013 14:53:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id gd11so274176vcb.16 for ; Fri, 07 Jun 2013 14:53:17 -0700 (PDT) X-Received: by 10.52.155.67 with SMTP id vu3mr173436vdb.94.1370641997500; Fri, 07 Jun 2013 14:53:17 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.10.206 with SMTP id pb14csp131436vcb; Fri, 7 Jun 2013 14:53:16 -0700 (PDT) X-Received: by 10.194.24.225 with SMTP id x1mr315655wjf.62.1370641996334; Fri, 07 Jun 2013 14:53:16 -0700 (PDT) Received: from mail-we0-x22d.google.com (mail-we0-x22d.google.com [2a00:1450:400c:c03::22d]) by mx.google.com with ESMTPS id cs6si10253494wib.84.2013.06.07.14.53.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Jun 2013 14:53:16 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::22d is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=2a00:1450:400c:c03::22d; Received: by mail-we0-f173.google.com with SMTP id x54so2637626wes.32 for ; Fri, 07 Jun 2013 14:53:15 -0700 (PDT) X-Received: by 10.180.75.41 with SMTP id z9mr329976wiv.22.1370641995815; Fri, 07 Jun 2013 14:53:15 -0700 (PDT) Received: from mai.home (AToulouse-654-1-404-219.w82-125.abo.wanadoo.fr. [82.125.3.219]) by mx.google.com with ESMTPSA id fu14sm24661498wic.8.2013.06.07.14.53.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Jun 2013 14:53:15 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl Cc: francescolavra.fl@gmail.com, lenb@kernel.org, linaro-kernel@lists.linaro.org, patches@linaro.org, linux-pm@vger.kernel.org Subject: [PATCH V4 2/2] cpuidle: Comment the driver's framework code Date: Fri, 7 Jun 2013 23:53:10 +0200 Message-Id: <1370641990-13884-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1370641990-13884-1-git-send-email-daniel.lezcano@linaro.org> References: <1370641990-13884-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQli4xkT/rkpG19hKrmWd81RB37mPkKyAqUpkYhIVwcADXCdDgPvVH1nka5JMDZ8InaQx3m8 X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Added kerneldoc and comments for the cpuidle framework driver's code. Signed-off-by: Daniel Lezcano --- [V4] - fixed kerneldoc comment format drivers/cpuidle/driver.c | 134 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 128 insertions(+), 6 deletions(-) diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index e75fa54..4cc5bc4 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -22,11 +22,26 @@ DEFINE_SPINLOCK(cpuidle_driver_lock); static DEFINE_PER_CPU(struct cpuidle_driver *, cpuidle_drivers); +/** + * __cpuidle_get_cpu_driver - returns the cpuidle driver tied with a cpu + * @cpu: the cpu handled by the driver + * + * Returns a pointer to struct cpuidle_driver, NULL if no driver has been + * registered for this driver + */ static struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu) { return per_cpu(cpuidle_drivers, cpu); } +/** + * __cpuidle_unset_driver - set the per cpu variable driver to NULL. + * @drv: a valid pointer to a struct cpuidle_driver + * + * For each cpu belonging to the driver's cpu mask, set the registered + * driver to NULL. If the specified driver is different from the registered + * one, the registered driver is untouched. + */ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv) { int cpu; @@ -40,6 +55,15 @@ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv) } } +/** + * __cpuidle_set_driver - assign to the per cpu variable the driver pointer + * @drv: a valid pointer to a struct cpuidle_driver + * + * For each cpus handled by the driver, belonging to the driver's cpumask, + * assign to the per cpu variable the driver pointer + * + * Returns 0 on success, -EBUSY if a driver was already assigned to a cpu. + */ static inline int __cpuidle_set_driver(struct cpuidle_driver *drv) { int cpu; @@ -61,11 +85,24 @@ static inline int __cpuidle_set_driver(struct cpuidle_driver *drv) static struct cpuidle_driver *cpuidle_curr_driver; +/** + * __cpuidle_get_cpu_driver - returns the global cpuidle driver pointer. + * @cpu: this parameter is ignored without the multiple driver support + * + * Returns a pointer to a struct cpuidle_driver, NULL if no driver was + * previously registered + */ static inline struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu) { return cpuidle_curr_driver; } +/** + * __cpuidle_set_driver - assign the global cpuidle driver variable + * @drv: a pointer to a struct cpuidle_driver + * + * Returns 0 on success, -EBUSY if the driver is already registered. + */ static inline int __cpuidle_set_driver(struct cpuidle_driver *drv) { if (cpuidle_curr_driver) @@ -76,6 +113,13 @@ static inline int __cpuidle_set_driver(struct cpuidle_driver *drv) return 0; } +/** + * __cpuidle_unset_driver - reset the global cpuidle driver variable + * @drv: a pointer to a struct cpuidle_driver + * + * Sets the global cpuidle variable to NULL, if the specified driver + * does not match the registered driver, the function will have no effect. + */ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv) { if (drv == cpuidle_curr_driver) @@ -84,21 +128,49 @@ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv) #endif +/** + * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer + * @arg: a void pointer, actually used to match the smp cross call api but used + * as a long with two values: + * - CLOCK_EVT_NOTIFY_BROADCAST_ON + * - CLOCK_EVT_NOTIFY_BROADCAST_OFF + * + * Sets the broadcast timer notification for the current cpu. This function + * is called per cpu context invoked by a smp cross call. It not supposed to be + * called directly. + */ static void cpuidle_setup_broadcast_timer(void *arg) { int cpu = smp_processor_id(); clockevents_notify((long)(arg), &cpu); } +/** + * __cpuidle_driver_init - initialize the driver's internal data + * @drv: a valid pointer to a struct cpuidle_driver + * + * Returns 0 on success, a negative error otherwise. + */ static int __cpuidle_driver_init(struct cpuidle_driver *drv) { int i; drv->refcnt = 0; + /* + * we default here to all cpu possible because if the kernel + * boots with some cpus offline and then we online one of them + * the cpu notifier won't know which driver to assign + */ if (!drv->cpumask) drv->cpumask = (struct cpumask *)cpu_possible_mask; + /* + * we look for the timer stop flag in the different states, + * so know we have to setup the broadcast timer. The loop is + * in reverse order, because usually the deeper state has this + * flag set + */ for (i = drv->state_count - 1; i >= 0 ; i--) { if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP)) @@ -111,6 +183,21 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv) return 0; } +/** + * __cpuidle_register_driver: registers the driver + * @drv: a valid pointer to a struct cpuidle_driver + * + * Does some sanity checks, initializes the driver, assigns the driver + * to the global cpuidle driver variable(s) and setup the broadcast + * timer if the cpuidle driver has some states which shutdown the + * local timer. + * + * Returns 0 on success, a negative error otherwise: + * * -EINVAL if the driver pointer is NULL + * * -EINVAL if the not idle states available + * * -ENODEV if the cpuidle framework is disabled + * * -EBUSY if the driver is already assigned to the global variables + */ static int __cpuidle_register_driver(struct cpuidle_driver *drv) { int ret; @@ -137,8 +224,13 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv) } /** - * cpuidle_unregister_driver - unregisters a driver - * @drv: the driver + * __cpuidle_unregister_driver - unregister the driver + * @drv: a valid pointer to a struct cpuidle_driver + * + * Checks the driver is no longer in use, resets the global cpuidle + * driver variable(s) and disable the timer broadcast notification + * mechanism if it was in use. + * */ static void __cpuidle_unregister_driver(struct cpuidle_driver *drv) { @@ -156,7 +248,13 @@ static void __cpuidle_unregister_driver(struct cpuidle_driver *drv) /** * cpuidle_register_driver - registers a driver - * @drv: the driver + * @drv: a pointer to a valid struct cpuidle_driver + * + * Registers the driver by taking a lock to prevent multiple callers + * to [un]register a driver at the same time. + * + * Returns 0 on success, a negative error otherwise (refer to the + * __cpuidle_register_driver). */ int cpuidle_register_driver(struct cpuidle_driver *drv) { @@ -172,7 +270,11 @@ EXPORT_SYMBOL_GPL(cpuidle_register_driver); /** * cpuidle_unregister_driver - unregisters a driver - * @drv: the driver + * @drv: a pointer to a valid struct cpuidle_driver + * + * Unregisters a driver by taking a lock to prevent multiple callers + * to [un]register a driver at the same time. The specified driver + * must match the driver currently registered. */ void cpuidle_unregister_driver(struct cpuidle_driver *drv) { @@ -183,7 +285,9 @@ void cpuidle_unregister_driver(struct cpuidle_driver *drv) EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); /** - * cpuidle_get_driver - return the current driver + * cpuidle_get_driver - returns the driver tied with the current cpu. + * + * Returns a struct cpuidle_driver pointer, or NULL if no driver is registered */ struct cpuidle_driver *cpuidle_get_driver(void) { @@ -199,7 +303,11 @@ struct cpuidle_driver *cpuidle_get_driver(void) EXPORT_SYMBOL_GPL(cpuidle_get_driver); /** - * cpuidle_get_cpu_driver - return the driver tied with a cpu + * cpuidle_get_cpu_driver - returns the driver registered with a cpu. + * @dev: a valid pointer to a struct cpuidle_device + * + * Returns a struct cpuidle_driver pointer, or NULL if no driver is registered + * for the specified cpu */ struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev) { @@ -210,6 +318,14 @@ struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev) } EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver); +/** + * cpuidle_driver_ref - gets a refcount for the driver + * + * This function takes a refcount for the driver assigned to the current cpu + * + * Returns a struct cpuidle_driver pointer, or NULL if no driver is registered + * for the current cpu + */ struct cpuidle_driver *cpuidle_driver_ref(void) { struct cpuidle_driver *drv; @@ -223,6 +339,12 @@ struct cpuidle_driver *cpuidle_driver_ref(void) return drv; } +/** + * cpuidle_driver_unref - puts down the refcount for the driver + * + * This function decrements the refcount for the driver assigned to the current + * cpu. + */ void cpuidle_driver_unref(void) { struct cpuidle_driver *drv = cpuidle_get_driver();