Received: by 10.223.185.116 with SMTP id b49csp830271wrg; Fri, 23 Feb 2018 07:28:14 -0800 (PST) X-Google-Smtp-Source: AH8x227/jGMAY9yB5+mzAiMyaQnhLIdInFJ53JsLAJ3VqepNy9xDTpWYOVeeWX/Fvy1Wkt2Gjif6 X-Received: by 10.99.123.92 with SMTP id k28mr1746029pgn.167.1519399694445; Fri, 23 Feb 2018 07:28:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519399694; cv=none; d=google.com; s=arc-20160816; b=HzVHlyS3P3KO7EkJTcmbwaXmTxENYjhGuNXpvgmVsklSxNSLqnJ/Hv5GwCBWfcIske LXtNgW1Itp/V8WonQ+o/mdG+2YqQLhIzMcF9L4JKV4+fpCcpJr69UZG773RGQFg0CHcv Br3bYozY0QI7+qWpBTzdZN3BOq92jDQVGB7zbJrwQBK+V3AID/SHZf6tRF3meU3YR+8c JTGVmAh50lFsOzN1XysAJB+Xja0JZXoYScUr+lPnn0zjuD39tDlD/RSLzj4OSnpb2+IE Zx3URvHuFuxxCMs40Y6fW4/YV/ZEuxtLm7Ka87VcuGmKISmmYDAJjAf8IDdnlAwq0NUt TEOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ef37xAo0niXcMm0v7hTlEG5FTVDeHN0/Bmv8iUEGuCc=; b=EvTFX3/Nu6lsT5WNqgY9MWaQkK+4ghuwYdZbljY9LONCG3Zo33SsgLN6Q6AXxUWXTS /4XeAhgmvEM17W0oA2ynoAeBmAJiElAX99kv/GdmUSe44eGhjmSU1ETDVKuCSBHTd5Xq 7mncBx6BejYpsn2EGM7k3MyYQJU4pE2PbQYKf0ahPZc02hORB+pZSWwb2WdpkJTu11oG hXfTFUPYqubL37HS/WEgyNjAQB8xlwaNNnnlKYIWsTzBhF9moZVrh5a5Na3vHOm4qgtu UR+SVFWermC8hHXAmqklqk919v9Mg6eLNrMml0Id882ZtzFO6h2l5beOy2mfy1G4YnOB x5yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HlqbvVaO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m62si1638910pga.507.2018.02.23.07.28.00; Fri, 23 Feb 2018 07:28:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HlqbvVaO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751985AbeBWP1S (ORCPT + 99 others); Fri, 23 Feb 2018 10:27:18 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:35251 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751360AbeBWP1R (ORCPT ); Fri, 23 Feb 2018 10:27:17 -0500 Received: by mail-io0-f195.google.com with SMTP id 30so10174142iog.2 for ; Fri, 23 Feb 2018 07:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ef37xAo0niXcMm0v7hTlEG5FTVDeHN0/Bmv8iUEGuCc=; b=HlqbvVaOQqYdI4jmzL4fki1FixH4ckwGIIJ14FZ+xMrn27S63F4kV9i+4jcnIh7EBq wYOyJb3ACAsfa15QwikBrapx9VqjNy2fFa5rDyf1mP3fWv4fKlkWSDVqY5ATRy5l39Jo FrbSXvsZTz4Rzh3Z8fkHiKb1iSoDDak9W3FdA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ef37xAo0niXcMm0v7hTlEG5FTVDeHN0/Bmv8iUEGuCc=; b=NlwcVoIDs7cQbqYYySxNBzxstQV0trDjgyV9aNAOIpAaisWzLXdt5R8mbvOcxTOYTC Sz8B9CgoJ56DEkv2S3fhSlodKwxh1HUrGfQogkwc7+7vs0S7vLFE22iLClXUIvxKQdn7 9H3nNDXFAV91RF3vbaFlHB0oV4NsMNvh7ilfK0lIjQrYSkEOpOdWnPRZJJAASo3EnWkh C5RIpXciR9NPGIglUj6HrNoekKXFveKSobWOvYf/0mnbbPARaBgHxIgtttNbm8qEuiSQ G9iFqyaoBMOlY1Tu4lQijyxwtToD4ikqUKcibtBI3nQ0YwFnEiv6fOIwWKewICtMjdax 2TCQ== X-Gm-Message-State: APf1xPA5vNDs/3/URayGJM+DMU/LCPB8wSDrqd4YEvy1G/PwPPDl3IYc Ih+dl5jPAgfDWA1tBYik1J9pRFXnvniSLV7wAHMNy6uaDa0= X-Received: by 10.107.29.205 with SMTP id d196mr2274836iod.18.1519399636146; Fri, 23 Feb 2018 07:27:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.50.83 with HTTP; Fri, 23 Feb 2018 07:26:55 -0800 (PST) In-Reply-To: <1519226968-19821-7-git-send-email-daniel.lezcano@linaro.org> References: <1519226968-19821-1-git-send-email-daniel.lezcano@linaro.org> <1519226968-19821-7-git-send-email-daniel.lezcano@linaro.org> From: Vincent Guittot Date: Fri, 23 Feb 2018 16:26:55 +0100 Message-ID: Subject: Re: [PATCH V2 6/7] thermal/drivers/cpu_cooling: Introduce the cpu idle cooling driver To: Daniel Lezcano Cc: Eduardo Valentin , Kevin Wangtao , Leo Yan , Amit Kachhap , linux-kernel , Javi Merino , Zhang Rui , Daniel Thompson , "open list:THERMAL" , Viresh Kumar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, On 21 February 2018 at 16:29, Daniel Lezcano wrote: > + > +/** > + * struct cpuidle_cooling_device - data for the idle cooling device > + * @cdev: a pointer to a struct thermal_cooling_device > + * @cpumask: a cpumask containing the CPU managed by the cooling device > + * @timer: a hrtimer giving the tempo for the idle injection cycles > + * @kref: a kernel refcount on this structure > + * @count: an atomic to keep track of the last task exiting the idle cycle > + * @idle_cycle: an integer defining the duration of the idle injection > + * @state: an normalized integer giving the state of the cooling device > + */ > +struct cpuidle_cooling_device { > + struct thermal_cooling_device *cdev; > + struct cpumask *cpumask; > + struct list_head node; > + struct hrtimer timer; > + struct kref kref; > + atomic_t count; > + unsigned int idle_cycle; > + unsigned int state; > +}; > + > +/** > + * @tsk: an array of pointer to the idle injection tasks > + * @waitq: the waiq for the idle injection tasks > + */ > +struct cpuidle_cooling_tsk { > + struct task_struct *tsk; > + wait_queue_head_t waitq; Why are you creating one wait_queue_head_t per cpu instead of one per cooling device and then save a pointer in the per cpu struct cpuidle_cooling_tsk ? Then, you can use wake_up_interruptible_all() to wake up all threads instead of using for_each_cpu ... wake_up_process() loop in cpuidle_cooling_wakeup() ? > +}; > + > +DEFINE_PER_CPU(struct cpuidle_cooling_tsk, cpuidle_cooling_tsk); > + > +static LIST_HEAD(cpuidle_cdev_list); > + > +/** > + * cpuidle_cooling_wakeup - Wake up all idle injection threads > + * @idle_cdev: the idle cooling device > + * > + * Every idle injection task belonging to the idle cooling device and > + * running on an online cpu will be wake up by this call. > + */ > +static void cpuidle_cooling_wakeup(struct cpuidle_cooling_device *idle_cdev) > +{ > + int cpu; > + struct cpuidle_cooling_tsk *cct; > + > + for_each_cpu_and(cpu, idle_cdev->cpumask, cpu_online_mask) { > + cct = per_cpu_ptr(&cpuidle_cooling_tsk, cpu); > + wake_up_process(cct->tsk); > + } > +} > + > +/** > + * cpuidle_cooling_wakeup_fn - Running cycle timer callback > + * @timer: a hrtimer structure > + * > + * When the mitigation is acting, the CPU is allowed to run an amount > + * of time, then the idle injection happens for the specified delay > + * and the idle task injection schedules itself until the timer event > + * wakes the idle injection tasks again for a new idle injection > + * cycle. The time between the end of the idle injection and the timer > + * expiration is the allocated running time for the CPU. > + * > + * Returns always HRTIMER_NORESTART > + */ > +static enum hrtimer_restart cpuidle_cooling_wakeup_fn(struct hrtimer *timer) > +{ > + struct cpuidle_cooling_device *idle_cdev = > + container_of(timer, struct cpuidle_cooling_device, timer); > + > + cpuidle_cooling_wakeup(idle_cdev); > + > + return HRTIMER_NORESTART; > +} > + > +/**