Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp349146imm; Tue, 5 Jun 2018 21:29:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIC/xF30jJ7NBby5NaaJ8qNAuIJClaq8XsLzoGu1euyCVXlxJUa9BWYfNo/qr9Ba+O1Lo2q X-Received: by 2002:a17:902:650a:: with SMTP id b10-v6mr1635724plk.45.1528259341501; Tue, 05 Jun 2018 21:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528259341; cv=none; d=google.com; s=arc-20160816; b=L967GjeZIvsJIWdQ/cmDCzad1CohUqIlDxDPGurY4md7ey+aBLwa+ZfdVgL6N3EaHk QCxTcbneB20zTLHc6k4PIrtdNggdec2voTbQogZezFo0vj2VMTuAM/mlbmwm14B66gha 3vRpvZaUhkvAvp6ib64IpB2Vq/0kYgZ9aUZo/SLAjy6NxcDCJYeluunI6QGC/TQxoHEU eJn/xJW5iNNCNqqJ17rA1s2I7KGCylW5HGiIsHXepUqnHMyfofBRnZYQhTvRmaNxqaf0 k00OPzlPLnrgu7P+7qJBjDcrfP2rknGRhsi/ZdQBzUSQXXDuzfsNmNPtX+yZmQs3dP7E AOdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=NpY6JsT7dvA6r73V+6ypMaV84dx5I41xXvsySeuU5eQ=; b=RiFkeOCFLkqxgdCHyaz/0IrlVYxqemIGiDPm3hE82q8VmTsgNOKJ9a8+kniM0VPeLI 4+5hBtj4dk1/c0zO3Ioc4FvDQ7H72rul1oY8nNsgIPnpbzgHORDk3k1O2dZOBYOCwDu3 IGY6gtkFTlztQN9fCP2fG5PhbCxi7mr/YAOHfOz6WEbiu+qQWj7r8gqrRn3xXXUiH4D0 kkHdjIg+ejYqUMHtTmuEiWsBxptqWs0qWWyRDRqAQ/B0SCPeu5IDuA5LSeDx1GUbmref Es2SQqUmYErArDIXD+Xbqmyhx1Gqp+xqIJsQHC2taSgiCsjdXNWjs7tmioasXxTgLm1M rnCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e1PQ3reE; 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 m12-v6si11452261pll.461.2018.06.05.21.28.47; Tue, 05 Jun 2018 21:29:01 -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=e1PQ3reE; 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 S1751700AbeFFE1N (ORCPT + 99 others); Wed, 6 Jun 2018 00:27:13 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:39899 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750783AbeFFE1M (ORCPT ); Wed, 6 Jun 2018 00:27:12 -0400 Received: by mail-pg0-f65.google.com with SMTP id w12-v6so2321302pgc.6 for ; Tue, 05 Jun 2018 21:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=NpY6JsT7dvA6r73V+6ypMaV84dx5I41xXvsySeuU5eQ=; b=e1PQ3reEAG5NMG3Hva80qvltFOZkiZ5st2IC3BD9a1d2BE5H6lisO+sEdE3Cxrqewu 3NJfKaEiNkmw1W1uLsv5AzYv/BgUA1RJWoC43j58F6LrguGhEp7vb/5TBK+8Gv7N491a /zvqBhuCCwSeOtMIlbp+aJdISM3VRh5pgYuYg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=NpY6JsT7dvA6r73V+6ypMaV84dx5I41xXvsySeuU5eQ=; b=Ez7z/UU38g7kU4WMJLBI1In+NGK+2LUm8LJvNVtJJYWcpn5tl0LyVUeZIfWKmwnW9/ EAS17Lbju967f28MHQBglIFLekl3EesecRXFpL7DwIYU/xKueuU2I7tyHaWSEJ1WdVXe pxYhb51X0CQJBgBYHV5lmJSmyU9JBuqY439PzrAv6H6QP+Oj1pxjPVxNzVeFzXOtp5vH XahcD9FSc8CGqROh5kXpei1tLEAXCqOhLMdkIbBaXUT6uIeg3bjEdGHgL+4Sw1ggoyr4 I7cMepvKyuL0TXMxZZqCBTEwtfWb9EShThaJWR4fsLb7sLNG1MOPQ4ToTCQdS44B2Hwm 1HNw== X-Gm-Message-State: APt69E2cB+gP56i/NxbqxRUZclNuYV5iKkgz5N4/UbGSL0JNs6B4vF9c O2++WjGqhoqjoF8Vu7ES1/3onQ== X-Received: by 2002:a62:3889:: with SMTP id f131-v6mr884003pfa.173.1528259231345; Tue, 05 Jun 2018 21:27:11 -0700 (PDT) Received: from localhost ([122.172.63.23]) by smtp.gmail.com with ESMTPSA id g20-v6sm80320974pfi.163.2018.06.05.21.27.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jun 2018 21:27:10 -0700 (PDT) Date: Wed, 6 Jun 2018 09:57:08 +0530 From: Viresh Kumar To: Daniel Lezcano 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" Subject: Re: [PATCH V5] powercap/drivers/idle_injection: Add an idle injection framework Message-ID: <20180606042708.mtwd66ecy2cnjp7a@vireshk-i7> References: <1528190208-22915-1-git-send-email-daniel.lezcano@linaro.org> <20180605103917.pyhhcobdvaivqv6g@vireshk-i7> <57d769f8-46ea-512e-8f89-a0439c9d053f@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57d769f8-46ea-512e-8f89-a0439c9d053f@linaro.org> User-Agent: NeoMutt/20180323-120-3dd1ac Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ? + + 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); + } +} -- viresh