Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp161430imj; Wed, 13 Feb 2019 06:22:44 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaj+x7VEjG/zyb46MubuU9cbON97YsRXtaCeT1ND6IMLoTojEZpJbOgz/EeHDWcTnB6boON X-Received: by 2002:a62:5007:: with SMTP id e7mr781225pfb.92.1550067763929; Wed, 13 Feb 2019 06:22:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550067763; cv=none; d=google.com; s=arc-20160816; b=OCKYX4SBCo2RTr7XpItTI0Lf4XRcClx6A1yp+68p1vOtMBWl/O6coTHsJlVkWZH4Fa f6U5kv9gUYyo0WNy+7aRXXj7SDA3vck2MF1p1UznO/thoBOCFggZ37YoqfpjzFMKlA8A rXCyeRnhsU5NzgrgVkZzUzKsNN/AeIqU6W5sqztscAgmzQYGIZkUiMEUdhPQzpv9Zm/i nhwVxrzhOyeFQk20svcrptdmd7TotD8Bk+jOAcOCIybmdPWTYAYeRgOkxD+c56Xax7Kp ZZEFcWt5CnTnNvCCxr6/IoVfUXXSaP6libpdl3Bg94IuN3p+J2b2VglN19dfXn1tBzOw h5UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type :content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:cc:to:subject:dkim-signature :dkim-filter; bh=bpPKzwesBV6HdybY3gutnR/+vzN1yzK8UODNlpERpxU=; b=n/opm16mtYS+NxNhkzqah9/t3DdMSP2WgvK7vzRXGCOK5JgrsCXziqIIkVwriNdtHZ F800JNnDP4Hdd7uB7RRiorJ6pIDpmQ6vLykxyQhipyGramfDHZnxgAu/BCDSzbWraFd1 qGTmBgYn+kwA0QARDUUDQkOQ8YK6zwpjhS3A/zRn4rj6ItIfHgm7Y7Tpv2/acirIP/J4 ZVx7SguBLh7H1cgueqUQTGpUQ6FdkQQxgxlZkRn2D9KS9XkypaywzkLnYlSWUKRfMXje gVVO4lMYRFboiS6eNJMCZu7VqeV+Gx06BN7KpkINN+7MpJd52sT4igIt14lqz4MVHKFp n20g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=DdkOrrrv; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s27si15218544pgm.501.2019.02.13.06.22.27; Wed, 13 Feb 2019 06:22:43 -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=@samsung.com header.s=mail20170921 header.b=DdkOrrrv; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388068AbfBMNAc (ORCPT + 99 others); Wed, 13 Feb 2019 08:00:32 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:32947 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730451AbfBMNAb (ORCPT ); Wed, 13 Feb 2019 08:00:31 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20190213130030euoutp02cf99455f8ccdf189dbee330a1a809757~C7e55DpEU0188801888euoutp02N for ; Wed, 13 Feb 2019 13:00:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190213130030euoutp02cf99455f8ccdf189dbee330a1a809757~C7e55DpEU0188801888euoutp02N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1550062830; bh=bpPKzwesBV6HdybY3gutnR/+vzN1yzK8UODNlpERpxU=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=DdkOrrrvrMdkCYnsvg+1+N/19ThVAFaSNy+mOCyJuHvOPibrH5fNjeFqZgK7LRRqw 6zgvY6q74vffkFvvoAZ3to84qqCR6Dy4R9V6/aZbE+zUPWhT2eI4i6+jr9Z6QJ1uuS 47YchJ5+9VtzCqrenUWErzMdL4nLVEmVtziq/yak= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20190213130029eucas1p2895b800a765a2bf64fa764cd85a3d577~C7e5F42El2946929469eucas1p2b; Wed, 13 Feb 2019 13:00:29 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 6A.DE.04806.CE4146C5; Wed, 13 Feb 2019 13:00:29 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20190213130028eucas1p2c91c56e8b8672b479417b5b3e6312233~C7e4S1h490426404264eucas1p2R; Wed, 13 Feb 2019 13:00:28 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20190213130028eusmtrp24e1af0d8f05cdd2bca6c94e2bf183d48~C7e4D9VQC0937809378eusmtrp29; Wed, 13 Feb 2019 13:00:28 +0000 (GMT) X-AuditID: cbfec7f5-367ff700000012c6-e2-5c6414ec7b4f Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D6.27.04284.CE4146C5; Wed, 13 Feb 2019 13:00:28 +0000 (GMT) Received: from [106.120.51.20] (unknown [106.120.51.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190213130027eusmtip1e5e198082688fdc003e82eef2bae39a0~C7e3iQgKZ0208302083eusmtip1z; Wed, 13 Feb 2019 13:00:27 +0000 (GMT) Subject: Re: [PATCH v2 0/2] drivers: devfreq: fix and optimize workqueue mechanism To: Matthias Kaehlcke Cc: Chanwoo Choi , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, b.zolnierkie@samsung.com, myungjoo.ham@samsung.com, kyungmin.park@samsung.com, m.szyprowski@samsung.com, s.nawrocki@samsung.com, joel@joelfernandes.org, chris.diamand@arm.com, Viresh Kumar From: Lukasz Luba Message-ID: <90bbff25-1c9c-127c-13a7-91a5f4fe666e@partner.samsung.com> Date: Wed, 13 Feb 2019 14:00:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190213003044.GV117604@google.com> Content-Language: en-US Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCKsWRmVeSWpSXmKPExsWy7djPc7pvRVJiDN71s1psnLGe1WLap8ss Fte/PGe1WNaganG26Q27xeVdc9gsPvceYbRYe+Quu8XnDY8ZLW43rmCzOPymHajrq4cDj8ea eWsYPWY3XGTxWPjpK6vHnWt72Dz6tqxi9Pi8SS6ALYrLJiU1J7MstUjfLoErY/PEmoI5LhVn P/9gaWCcYdbFyMEhIWAisX5/TBcjF4eQwApGiabpvWwQzhdGifvtW1ghnM+MEiu7VjJ1MXKC dTQe2wVVtZxRYs/8rVDOW0aJidNfs4JUCQuESKzpO8AMYosIaEg8+X2eEaSIWeAAk8SzpSvY QJazCehJ7FhVCFLDK+AmsaD/FQuIzSKgKnGg5yUbiC0qECFxuPcdI0SNoMTJmU/AajgFDCXu NN0Bm88sIC5x68l8JghbXqJ562xmkF0SAtfYJTa+XM0OcbaLxIv+dywQtrDEq+NboOIyEv93 zod6rVjibMcqNgi7RqL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h4K4RSYoRYE8uKK3MPMUpwMCuJ8H7hAwrxpiRWVqUW5ccXleakFh9iNAV6 biKzlGhyPjCR5JXEG5oamltYGpobmxubWSiJ8543qIwSEkhPLEnNTk0tSC2C6WPi4JRqYAxh Ts2azhfwRiDW1tntnfzTuMeOq9Jmu3h7Cl/VEVA78yrCSrbD16r/RyVr2qO8p1djZr//uubr 2yxnVaGctF4/PuYNd1bGGUr91hM4FPrsgWVN+KrKlS87r4RmnN69cYbfvodFBROW1ZTs39RT Ii+mpf5L99zF1KL/pluzFvXsSn/ZnMOrp8RSnJFoqMVcVJwIADo1fansAgAA X-CMS-MailID: 20190213130028eucas1p2c91c56e8b8672b479417b5b3e6312233 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190211153030eucas1p19bd9a7eca565ca066ab00dc2243cfb46 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190211153030eucas1p19bd9a7eca565ca066ab00dc2243cfb46 References: <1549899005-7760-1-git-send-email-l.luba@partner.samsung.com> <26e38213-630f-94bc-ff80-1cad708c7f83@samsung.com> <20190212193229.GT117604@google.com> <1356584e-1812-6768-72af-931c07d925a8@partner.samsung.com> <20190213003044.GV117604@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Matthias, On 2/13/19 1:30 AM, Matthias Kaehlcke wrote: > Hi Lukasz, > > On Tue, Feb 12, 2019 at 10:20:07PM +0100, Lukasz Luba wrote: >> Hi Matthias, >> >> On 2/12/19 8:32 PM, Matthias Kaehlcke wrote: >>> Hi, >>> >>> On Tue, Feb 12, 2019 at 02:46:24PM +0900, Chanwoo Choi wrote: >>>> Hi Lukasz, >>>> >>>> On 19. 2. 12. 오전 12:30, Lukasz Luba wrote: >>>>> This patch set changes workqueue related features in devfreq framework. >>>>> First patch switches to delayed work instead of deferred. >>>>> The second switches to regular system work and deletes custom 'devfreq'. >>>>> >>>>> Using deferred work in this context might harm the system performance. >>>>> When the CPU enters idle, deferred work is not fired. The devfreq device's >>>>> utilization does not have to be connected with a particular CPU. >>>>> The drivers for GPUs, Network on Chip, cache L3 rely on devfreq governor. >>>>> They all are missing opportunity to check the HW state and react when >>>>> the deferred work is not fired. >>>>> A corner test case, when Dynamic Memory Controller is utilized by CPUs running >>>>> on full speed, might show x5 worse performance if the crucial CPU is in idle. >>>> >>>> The devfreq framework keeps the balancing between performance >>>> and power-consumption. It is wrong to focus on only either >>>> performance or power. >>>> >>>> This cover-letter focus on the only performance without any power-consumption >>>> disadvantages. It is easy to raise the performance with short sampling rate >>>> with polling modes. To get the performance, it is good as short as possible >>>> of period. >>>> >>>> Sometimes, when cpu is idle, the device might require the busy state. >>>> It is very difficult to catch the always right timing between them. >>>> >>>> Also, this patch cannot prevent the unneeded wakeup from idle state. >>>> Apparently, it only focuses on performance without considering >>>> the power-consumption disadvantage. In the embedded device, >>>> the power-consumption is very important point. We can not ignore >>>> the side effect. >>>> >>>> Always, I hope to improve the devfreq framwork more that older. >>>> But, frankly, it is difficult to agree because it only consider >>>> the performance without considering the side-effect. >>>> >>>> The power management framework always have to consider >>>> the power-consumption issue. This point is always true. >>> >>> I missed the impact of forcing a CPU out of an idle state and/or not >>> allowing it to enter a more power efficient state. I agree that this >>> should be avoided. >> It would be good to have some real world scenarios for comparison: >> w/ and w/o this change, i.e. it is 5% or 50% more power used. > > If you have data please share :) I will try to measure it. I have some data which refer to CPU hotplug and generic data regarding ARM big.LITTLE. It is a mobile on my desk. When one CPU of ARM big is sent offline power drops ~12mW comparing to WFI idle which was previous state. The same for LITTLE ~12mW. When the last CPU in the cluster is sent offline, whole culster is switched off and power drops ~50mW. The LITTLE core can consume ~250mW at max speed. Energy Aware Scheduler is now merged IIRC, so if it has to choose which core wake up for idle, it will take LITTLE not big. For older platforms which has Cortex-A9 500mW is also better estimation. > > Though I also imagine there will be quite some variation between > different systems/platforms. True. > >> I have patches that tries to mitigate wake-ups when there is small >> utilization. Let's make it tunable and involve driver developers. >> They will decide how much impact on the system power usage they >> introduce. > > Great! > >>> I wonder if using a power-efficient workqueue could help here: >>> >>> Instead of running work on the local CPU, the workqueue core asks the >>> scheduler to provide the target CPU for the work queued on unbound >>> workqueues (which includes those marked as power-efficient). So they >>> will not get pinned on a single CPU as can happen with regular >>> workqueues. >>> >>> https://lwn.net/Articles/731052/ >>> >>> >>> Since this series also changes from a custom to system workqueue it >>> seems worth to mention that there are power-efficient system workqueues: >>> >>> system_power_efficient_wq >>> system_freezable_power_efficient_wq >>> >>> >>> In case a power-efficient workqueue is suitable in principle there >>> would still be a problem though: the feature is currently disabled by >>> default, hence devfreq couldn't really rely on it. It is enabled in >>> the arm64 defconfig though, so at least devices on this architecture >>> would benefit from it. Also power-efficient workqueues might be >>> enabled by default in the future as the scheduler becomes more energy >>> aware. >> Regarding this CPU idle cost worries. >> IIRC the new energy model does not even consider idle costs of the CPU. >> It would be good to know the measurements, i.e. worst case scenario: >> waking up 1 (of 4 or 8) CPU from idle 30 times per second for let's >> say 100 us. It is 3 ms / 1000 ms * running energy cost i.e. 250mW. >> Thus, 0.75mW. > > I'm not an expert in this area, but your example seems too optimistic > You are just accounting for the pure runtime, not for the cost of > entering and exiting an idle state. Let's take a SDM845 idle state as > example: > > C0_CPU_PD: c0-power-down { > ... > entry-latency-us = <350>; > exit-latency-us = <461>; > min-residency-us = <1890>; > ... > }; > > https://patchwork.kernel.org/patch/10661319/ > > That's 811us for entering and exiting the idle state. At an > intermediate OPP (1.8 GHz) the power consumption is 505mW, according > to the Energy Model. I'm ignoring the actual execution time, since I > tend to agree with you that the monitoring should be done, unless it > has a really unreasonable cost. That leaves us with 30 * 811us = > 24.3ms and 24.3ms / 1000 ms * 505mW = 12.3mW. You are probably taking ARM 'big' core wake-up from deeper that WFI idle. I was referring to ARM LITTLE 250mW. It is also not 100% that the schedule work will wake up CPU which is currently in deepest idle. A short array would create a better picture of the use cases. The question is also probability of occurrence for each of these cases. For first two CPU state it would be a power cost lost during additional rescheduling to/from workqueue task, which takes i.e. 2*5 us * 30 times. CPU state ->| running | idle | idle clock | idle, pwr | ------------| (C0) | WFI (C1)| gated (C2)| gated (C3) | architecture| | | | | ------V----------------------------------------------------- ARM big | <1mW | <1mW | ~12mW | ~12mW | ARM LITTLE | <1mW | <1mW | ~6mW | ~6mW | MIPS PowerPC > >> In my opinion it is not a big cost. In most cases the system is still >> doing some other work. It is worth to mention here that on mobiles >> when the power button is hit the full suspend is called which freezes >> all tasks, devices and power consumption is ~15mW. Thus, the system >> suspend is out of scope here. > > I agree that system suspend is out of scope. > >> As I replayed to Chanwoon for the same email: in my opinion current >> devfreq is broken. >> It was probably developed in times where there was 1 CPU (maybe 2) >> and idle state of CPU would be a good hint to not to check devfreq >> devices. > > IIUC the use of a power-efficient workqueues would address the problem > of waking up a CPU in idle state, however as mentioned earlier by > default this feature is disabled (except for arm64). How about > switching to system_power_efficient_wq and use INIT_DELAYED_WORK if > CONFIG_WQ_POWER_EFFICIENT_DEFAULT=y (or check if the workqueue in > question has WQ_UNBOUND set?) and INIT_DEFERRABLE_WORK otherwise? It's > not ideal, but a possible improvement. I think it would be to complicated to maintain because different platforms might use different mechanisms. I would suggests that we could just follow mechanism in thermal framework. I have never faced any issue with delayed work there, while working on IPA. They use 'system_freezable_power_efficient_wq' and INIT_DELAYED_WORK(). https://elixir.bootlin.com/linux/v5.0-rc6/source/drivers/thermal/thermal_core.c#L293 https://elixir.bootlin.com/linux/v5.0-rc6/source/drivers/thermal/thermal_core.c#L1281 They have these two polling intervals, though. Regards, Lukasz > > Cheers > > Matthias > >