From patchwork Fri Sep 7 10:19:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 11232 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A363723E41 for ; Fri, 7 Sep 2012 10:19:52 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 3D050A18DA0 for ; Fri, 7 Sep 2012 10:19:52 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id j25so2827276iaf.11 for ; Fri, 07 Sep 2012 03:19:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=TGIm0SlVo/4M9GaPIqHL24eYtybkjNU0JwwT0E0BLuA=; b=ItwgRnDrmCSBaERuD1ZfCRd7XzEjUbPhueh6a18YyJfhsohVPJA3F2X8I14vBKBK4I pY7Uq31i/WTfJlc51dVqTPO/ynBYm4RbjpvwG0fWUjCgkHotTZR6ACsiJ3Zcw8u2Z/K7 lEl0XsyZezZDUsqndhljJpviyl66S3iwMZVnqGLoQxX36KkWS6DyFCdzf0JFNmTpTfYI YeyOf2PVIMl9gGEMgRs/PZYoTkzRH6CMMOD3xzNmci/2j/hGkfaSq8ovXplL6EmIUAeu /terdXyq9RFjpzLVoTfHaxDarpgdOJLSd6a71mfJ+Y+6/CqzmkSUWfjUapblfPkn7vZO cRKg== Received: by 10.50.195.134 with SMTP id ie6mr7341696igc.28.1347013192013; Fri, 07 Sep 2012 03:19:52 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp371152igc; Fri, 7 Sep 2012 03:19:51 -0700 (PDT) Received: by 10.204.133.194 with SMTP id g2mr2327928bkt.13.1347013190520; Fri, 07 Sep 2012 03:19:50 -0700 (PDT) Received: from mail-bk0-f50.google.com (mail-bk0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id hy16si4637905bkc.57.2012.09.07.03.19.50 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 07 Sep 2012 03:19:50 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: by mail-bk0-f50.google.com with SMTP id j5so1367058bkw.37 for ; Fri, 07 Sep 2012 03:19:50 -0700 (PDT) Received: by 10.205.122.134 with SMTP id gg6mr2302331bkc.102.1347013189673; Fri, 07 Sep 2012 03:19:49 -0700 (PDT) Received: from localhost.localdomain (AToulouse-651-1-16-21.w92-149.abo.wanadoo.fr. [92.149.191.21]) by mx.google.com with ESMTPS id n5sm3018481bkv.14.2012.09.07.03.19.47 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 07 Sep 2012 03:19:48 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl, lenb@kernel.org Cc: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, patches@linaro.org, linaro-dev@lists.linaro.org, pdeschrijver@nvidia.com, lorenzo.pieralisi@arm.com Subject: [PATCH 5/6] cpuidle : use per cpuidle device cpu states Date: Fri, 7 Sep 2012 12:19:31 +0200 Message-Id: <1347013172-12465-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1347013172-12465-1-git-send-email-daniel.lezcano@linaro.org> References: <1347013172-12465-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQmRV9YFhGx/kYv4IPaVFHrrj6bmLB6iK1x9YKw7OKvNkOc2zWA3zNsulZngSp9SVwYRZb4V We have the cpuidle states pointer stored in the cpuidle device structure. This patch use this pointer instead of the driver's one. Signed-off-by: Daniel Lezcano Acked-by: Peter De Schrijver Tested-by: Peter De Schrijver --- drivers/cpuidle/cpuidle.c | 17 +++++++++-------- drivers/cpuidle/governors/ladder.c | 22 +++++++++++----------- drivers/cpuidle/governors/menu.c | 8 ++++---- drivers/cpuidle/sysfs.c | 3 +-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index ef0e936..062f54e 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -45,7 +45,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev); static inline int cpuidle_enter(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { - struct cpuidle_state *target_state = &drv->states[index]; + struct cpuidle_state *target_state = &dev->states[index]; return target_state->enter(dev, drv, index); } @@ -76,8 +76,8 @@ int cpuidle_play_dead(void) return -ENODEV; /* Find lowest-power state that supports long-term idle */ - for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) { - struct cpuidle_state *s = &drv->states[i]; + for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) { + struct cpuidle_state *s = &dev->states[i]; if (s->power_usage < power_usage && s->enter_dead) { power_usage = s->power_usage; @@ -86,7 +86,7 @@ int cpuidle_play_dead(void) } if (dead_state != -1) - return drv->states[dead_state].enter_dead(dev, dead_state); + return dev->states[dead_state].enter_dead(dev, dead_state); return -ENODEV; } @@ -281,9 +281,9 @@ static int poll_idle(struct cpuidle_device *dev, return index; } -static void poll_idle_init(struct cpuidle_driver *drv) +static void poll_idle_init(struct cpuidle_device *dev) { - struct cpuidle_state *state = &drv->states[0]; + struct cpuidle_state *state = &dev->states[0]; snprintf(state->name, CPUIDLE_NAME_LEN, "POLL"); snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE"); @@ -295,7 +295,7 @@ static void poll_idle_init(struct cpuidle_driver *drv) state->disabled = false; } #else -static void poll_idle_init(struct cpuidle_driver *drv) {} +static void poll_idle_init(struct cpuidle_device *dev) {} #endif /* CONFIG_ARCH_HAS_CPU_RELAX */ /** @@ -317,6 +317,7 @@ int cpuidle_enable_device(struct cpuidle_device *dev) return 0; if (!drv || !cpuidle_curr_governor) return -EIO; + if (!dev->state_count) { dev->state_count = drv->state_count; dev->states = drv->states; @@ -331,7 +332,7 @@ int cpuidle_enable_device(struct cpuidle_device *dev) cpuidle_enter_ops = drv->en_core_tk_irqen ? cpuidle_enter_tk : cpuidle_enter; - poll_idle_init(drv); + poll_idle_init(dev); if ((ret = cpuidle_add_state_sysfs(dev))) return ret; diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c index 9b78405..0783f84 100644 --- a/drivers/cpuidle/governors/ladder.c +++ b/drivers/cpuidle/governors/ladder.c @@ -79,19 +79,19 @@ static int ladder_select_state(struct cpuidle_driver *drv, last_state = &ldev->states[last_idx]; - if (drv->states[last_idx].flags & CPUIDLE_FLAG_TIME_VALID) { + if (dev->states[last_idx].flags & CPUIDLE_FLAG_TIME_VALID) { last_residency = cpuidle_get_last_residency(dev) - \ - drv->states[last_idx].exit_latency; + dev->states[last_idx].exit_latency; } else last_residency = last_state->threshold.promotion_time + 1; /* consider promotion */ - if (last_idx < drv->state_count - 1 && - !drv->states[last_idx + 1].disabled && + if (last_idx < dev->state_count - 1 && + !dev->states[last_idx + 1].disabled && !dev->states_usage[last_idx + 1].disable && last_residency > last_state->threshold.promotion_time && - drv->states[last_idx + 1].exit_latency <= latency_req) { + dev->states[last_idx + 1].exit_latency <= latency_req) { last_state->stats.promotion_count++; last_state->stats.demotion_count = 0; if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) { @@ -102,13 +102,13 @@ static int ladder_select_state(struct cpuidle_driver *drv, /* consider demotion */ if (last_idx > CPUIDLE_DRIVER_STATE_START && - (drv->states[last_idx].disabled || + (dev->states[last_idx].disabled || dev->states_usage[last_idx].disable || - drv->states[last_idx].exit_latency > latency_req)) { + dev->states[last_idx].exit_latency > latency_req)) { int i; for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) { - if (drv->states[i].exit_latency <= latency_req) + if (dev->states[i].exit_latency <= latency_req) break; } ladder_do_selection(ldev, last_idx, i); @@ -144,8 +144,8 @@ static int ladder_enable_device(struct cpuidle_driver *drv, ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START; - for (i = 0; i < drv->state_count; i++) { - state = &drv->states[i]; + for (i = 0; i < dev->state_count; i++) { + state = &dev->states[i]; lstate = &ldev->states[i]; lstate->stats.promotion_count = 0; @@ -154,7 +154,7 @@ static int ladder_enable_device(struct cpuidle_driver *drv, lstate->threshold.promotion_count = PROMOTION_COUNT; lstate->threshold.demotion_count = DEMOTION_COUNT; - if (i < drv->state_count - 1) + if (i < dev->state_count - 1) lstate->threshold.promotion_time = state->exit_latency; if (i > 0) lstate->threshold.demotion_time = state->exit_latency; diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 5b1f2c3..3a9a9bd 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -281,7 +281,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) * unless the timer is happening really really soon. */ if (data->expected_us > 5 && - !drv->states[CPUIDLE_DRIVER_STATE_START].disabled && + !dev->states[CPUIDLE_DRIVER_STATE_START].disabled && dev->states_usage[CPUIDLE_DRIVER_STATE_START].disable == 0) data->last_state_idx = CPUIDLE_DRIVER_STATE_START; @@ -289,8 +289,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) * Find the idle state with the lowest power while satisfying * our constraints. */ - for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) { - struct cpuidle_state *s = &drv->states[i]; + for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) { + struct cpuidle_state *s = &dev->states[i]; struct cpuidle_state_usage *su = &dev->states_usage[i]; if (s->disabled || su->disable) @@ -338,7 +338,7 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) struct menu_device *data = &__get_cpu_var(menu_devices); int last_idx = data->last_state_idx; unsigned int last_idle_us = cpuidle_get_last_residency(dev); - struct cpuidle_state *target = &drv->states[last_idx]; + struct cpuidle_state *target = &dev->states[last_idx]; unsigned int measured_us; u64 new_factor; diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c index 5f809e3..6b20929 100644 --- a/drivers/cpuidle/sysfs.c +++ b/drivers/cpuidle/sysfs.c @@ -363,14 +363,13 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device) { int i, ret = -ENOMEM; struct cpuidle_state_kobj *kobj; - struct cpuidle_driver *drv = cpuidle_get_driver(); /* state statistics */ for (i = 0; i < device->state_count; i++) { kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL); if (!kobj) goto error_state; - kobj->state = &drv->states[i]; + kobj->state = &device->states[i]; kobj->state_usage = &device->states_usage[i]; init_completion(&kobj->kobj_unregister);