Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp623936imm; Wed, 6 Jun 2018 03:24:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKOAtRSck0JfcKAWuTaNvDiwGnXHireUs0Vg2A/shejqcoPwB0mJox5FmFg3fPauU0vaTaO X-Received: by 2002:a62:3e11:: with SMTP id l17-v6mr1902612pfa.18.1528280651002; Wed, 06 Jun 2018 03:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528280650; cv=none; d=google.com; s=arc-20160816; b=CiolOtwY2GgOYFm4mPuPc7poIDlRivO/JTVXCBx+fst/9cvRFeycJ8AvbUB0MYCs0J lr9ql+lo3wcK6J+9yKWh3sePpgPympp4kI3vJuZc2EdJs8d9mcabHxLazwA0LYqnhcfp 2gRHtfP/HXFVZsFqMUkBCzyp8dxWEEbNzZVX+Kz8EnXXfVvpohendQrzhcIPIF57XlcA xdlOqKTxLyYGPH2yIHqJBvCuB4/PADMlWZkkzbpiXvGgfTBXeQJlBMNycHNucaNhJ3wr yheJP/NEvqzEX5iccBhzqa5f65d5V9gKOXDdOME4PbzPpmhwkwQ59zzCAOf93x0Y1Dsj yoCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=PY2E1s1/2oZHh3WZsz/0iwKR3O1ZK7jUKH/DxU5K5To=; b=xaB6DHYN/7S9tK8TOzp9Sl4FIKTpFV26Dso/DygaRv2a8arDTN1RFbO/GK/nLUd7Nw T1RQtKoF+knjlIZusyM+z7BIN4ObRUygp8tNtiVQN2HMS4HuZ9mY9ZerOVvb/gRrp5Tf EK1eQ52MuZd2COrFaf1i0DEVfpUUESp93+BZ284SdWUQMk0CaiRxKEZ8VWI8Es8t9D/M S09NRQj6uu1m7FjYW5lp7Z5Y4ehORQ7RPvCk67Myyr7XzA3uTy2kWYMN8t3pABYTQvet hsuEpLB5sSvapBLpN0ah1zDmNZ0HPF2RSK+JeLDazNpWT7vdEnjw6VAdUVZw5ccP2s5a Q4VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fNcgha0F; 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 b26-v6si24425272pgw.394.2018.06.06.03.23.56; Wed, 06 Jun 2018 03:24:10 -0700 (PDT) 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=fNcgha0F; 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 S932434AbeFFKWL (ORCPT + 99 others); Wed, 6 Jun 2018 06:22:11 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:51283 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932304AbeFFKWK (ORCPT ); Wed, 6 Jun 2018 06:22:10 -0400 Received: by mail-wm0-f67.google.com with SMTP id r15-v6so10465749wmc.1 for ; Wed, 06 Jun 2018 03:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=PY2E1s1/2oZHh3WZsz/0iwKR3O1ZK7jUKH/DxU5K5To=; b=fNcgha0FcM0gWuYJEfhKdAJw93+5Pr2Du4CLDTZNOY25xwkoqDD8om6PPjDX04HTI8 o988b9jWI0tYnHNIDIwKktLpWKjgayp85kBp337UY0fCcQG1iJlth2bqkLN3U44XlkHm XJuiSO+fmy5h9HBKs75sCLZKBp4HOxoYcZdwM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PY2E1s1/2oZHh3WZsz/0iwKR3O1ZK7jUKH/DxU5K5To=; b=jHw2E2ue4eM6dseO9AtPHARmorhjxxnb1smZGFB0/VMMSIEBlGYdsTTxMGlHFTdw0e cnaQXONQ7XEbrwA+vQ711QIgyMImN07xhPS7B6WStY1Eiopd8oiVVLCJqzZMYlxCd5U/ Uf9RJ4t5nActOhWwSKCkDoJx1/Ie+q0QDgGr/yB0ZicKmK8IQJP4d8/lTrd34NVHwMZH +9N0d/IL4LvvJLyhHkrRnXkReJRJwhdZfVWnTiYKj2EnY8nxvq/YK9J8kp7XxOf3ZpbZ r1KZwgkGekUQcNMHg7PpjvJ1nFt1Xk4gos5FTNkEQFtIbqD9IfrMXuV/kdEKQpZU+5nX ddQw== X-Gm-Message-State: APt69E32sqm1LloRnWGE56dzCfmR+XxZ3S6TCMytfdROClxlc7VHWs2M +yWNLANFX5aaJmClZXcyydj7FA== X-Received: by 2002:a1c:6b51:: with SMTP id g78-v6mr1412738wmc.149.1528280528874; Wed, 06 Jun 2018 03:22:08 -0700 (PDT) Received: from ?IPv6:2001:41d0:fe90:b800:95b6:dc9b:e2e5:1028? ([2001:41d0:fe90:b800:95b6:dc9b:e2e5:1028]) by smtp.googlemail.com with ESMTPSA id y5-v6sm6256364wrp.51.2018.06.06.03.22.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jun 2018 03:22:07 -0700 (PDT) Subject: Re: [PATCH V5] powercap/drivers/idle_injection: Add an idle injection framework To: Viresh Kumar Cc: rjw@rjwysocki.net, linux-kernel@vger.kernel.org, Eduardo Valentin , Javi Merino , Leo Yan , Kevin Wangtao , Vincent Guittot , Rui Zhang , Daniel Thompson , "open list:POWER MANAGEMENT CORE" References: <1528190208-22915-1-git-send-email-daniel.lezcano@linaro.org> <20180605103917.pyhhcobdvaivqv6g@vireshk-i7> <57d769f8-46ea-512e-8f89-a0439c9d053f@linaro.org> <20180606042708.mtwd66ecy2cnjp7a@vireshk-i7> From: Daniel Lezcano Message-ID: <2bebd1bc-e1ad-6d22-ad1e-aee2cf8ba878@linaro.org> Date: Wed, 6 Jun 2018 12:22:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180606042708.mtwd66ecy2cnjp7a@vireshk-i7> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/06/2018 06:27, Viresh Kumar wrote: > On 05-06-18, 16:54, Daniel Lezcano wrote: >> On 05/06/2018 12:39, Viresh Kumar wrote: >> I don't think you are doing a mistake. Even if this can happen >> theoretically, I don't think practically that is the case. >> >> The play_idle() has 1ms minimum sleep time. >> >> The scenario you are describing means: >> >> 1. the loop in idle_injection_wakeup() takes more than 1ms to achieve > > There are many ways in which idle_injection_wakeup() can get called. > > - from hrtimer handler, this happens in softirq context, right? So interrupts > can still block the handler to run ? > > - from idle_injection_start(), process context. RT or DL or IRQ activity can > block the CPU for long durations sometimes. > >> 2. at the same time, the user of the idle injection unregisters while >> the idle injection is acting precisely at CPU0 and exits before another >> task was wakeup by the loop in 1. more than 1ms after. >> >> >From my POV, this scenario can't happen. > > Maybe something else needs to be buggy as well to make this crap happen. > >> Anyway, we must write rock solid code > > That's my point. > >> so may be we can use a refcount to >> protect against that, so instead of freeing in unregister, we refput the >> ii_dev pointer. > > I think the solution can be a simple change in implementation of > idle_injection_wakeup(), something like this.. > > +static void idle_injection_wakeup(struct idle_injection_device *ii_dev) > +{ > + struct idle_injection_thread *iit; > + int cpu; > + > + for_each_cpu_and(cpu, ii_dev->cpumask, cpu_online_mask) > + atomic_inc(&ii_dev->count); > > + > + mb(); //I am not sure but I think we need some kind of barrier here ? (mb() are done in the atomic operations AFAICT). What about: get_online_cpus(); nr_tasks = cpumask_weight( cpumask_and(ii_dev->cpumask, cpu_online_mask); atomic_set(&ii_dev->count, nr_tasks); for_each_cpu_and(cpu, ii_dev->cpumask, cpu_online_mask) { iit = per_cpu_ptr(&idle_injection_thread, cpu); iit->should_run = 1; wake_up_process(iit->tsk); } put_online_cpus(); ? I'm wondering if we can have a CPU hotplugged right after the 'put_online_cpus', resulting in the 'should park' flag set and then the thread goes in the kthread_parkme instead of jumping back the idle injection function and decrease the count, leading up to the timer not being set again. -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog