Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1681485ybi; Sat, 8 Jun 2019 15:56:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6JcN+Q2W62N676CR/m8kAtmiDwpPZ04yrYgC7H3cgXVLmiQH/xUh95tybv0Z8tCeO51To X-Received: by 2002:a63:2325:: with SMTP id j37mr9103039pgj.137.1560034580253; Sat, 08 Jun 2019 15:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560034580; cv=none; d=google.com; s=arc-20160816; b=jiVLsSR/NKaVeFjjd0quxFdDJRmKccoWnBNVpUt/octsS6uqyBTx964U1bYUdE+Gj9 +mbaslh2z2Sk4zMVSdIHmDfbxf8e9KOxbu4Yd4owH1+tEY5kMDZz2tFuagbZf4ZsaOSd CgibNQdj+0Yr0or1I174yHbdTBJJqciC4NjmydRX6vsL3Xc6sUWhGurab6H7BVHGWbLu 1ADxM6YVrJLnQy6l/P/IXXHbfmJAxkk0soA6wYoKfeMaYj93IW7QkGPs8W+a/v1N7eNP bb4+3SMxBPMIEUxx3mRHnjigyX/W/htckkKFMewh3kyb54fjUGJZ3yOOLiiOPEIcKLpT 3RqA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=CtFuq5rZ3nCxoioD1NwywW3jvi36W5CcbNhclRP4PJc=; b=JNZ6FETWDQyCczuAuu6BFlUBCb5f4HdrrctKrEeqSlbWKLn7Ptgzm953eJUygOCZpq j42KMKBCOBooanZvE6LR1Nvz8fpIrIw48rwHao9x9w9hid7e3yBt5gfv3p+7ICOHk2mf Jw8/i2YlpEtctY5DpkHOBdjOCoEtevELqYNeHd7NayhNflA5QUZdlKbO1IOg+Qr4bmXM Q9wI3kVaaOSWlxvG18m3IdgNZzxn2MulkH7TVBjM6ViruAlPbItAR+FbrNTXDSaltfbe oA4xdr1NtRZHg67/wZn46UlPwObaZREb6spJkh3UyRXOl9vELhi5fmS1wNbNGZgtUMFX GdQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RFbAfSy8; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g64si5522552pgc.555.2019.06.08.15.55.33; Sat, 08 Jun 2019 15:56:20 -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=@kernel.org header.s=default header.b=RFbAfSy8; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727585AbfFHWuq (ORCPT + 99 others); Sat, 8 Jun 2019 18:50:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:60202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727486AbfFHWuq (ORCPT ); Sat, 8 Jun 2019 18:50:46 -0400 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43C41216C4 for ; Sat, 8 Jun 2019 22:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560034245; bh=RLFBR9HbCoZXjl+6UXtsjw558AVzz+Q3/8n2Pf7zvAM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RFbAfSy8JStAzzVb2aoLeOgdbhW5Z09kxVhBPjGPRzmofb5FNLr7h8p8s9PS5fBds ppHhFjkghm8nI0OMDnY4Cud1LJWeobfNER+NG2zSvgDP6mqJI4Er2RjUZuCo3tQ9QV LvcnuP3isSBanZaCEk1JQ25hskdzYkfC72kj0I6g= Received: by mail-wm1-f44.google.com with SMTP id a15so5217691wmj.5 for ; Sat, 08 Jun 2019 15:50:45 -0700 (PDT) X-Gm-Message-State: APjAAAW6Wh1moBLkjJBxd2evdBKakF4J297xiy/DmcDnGF6cmCOA5AzM XPM5IjmfO0akVm46ZqAIlWb5Fxdt9H2IOGncrUqyqA== X-Received: by 2002:a1c:9a53:: with SMTP id c80mr7754960wme.173.1560034243802; Sat, 08 Jun 2019 15:50:43 -0700 (PDT) MIME-Version: 1.0 References: <1559944837-149589-1-git-send-email-fenghua.yu@intel.com> <1559944837-149589-4-git-send-email-fenghua.yu@intel.com> In-Reply-To: <1559944837-149589-4-git-send-email-fenghua.yu@intel.com> From: Andy Lutomirski Date: Sat, 8 Jun 2019 15:50:32 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 3/5] x86/umwait: Add sysfs interface to control umwait C0.2 state To: Fenghua Yu Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Andy Lutomirski , Ashok Raj , Tony Luck , Ravi V Shankar , linux-kernel , x86 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 On Fri, Jun 7, 2019 at 3:10 PM Fenghua Yu wrote: > > C0.2 state in umwait and tpause instructions can be enabled or disabled > on a processor through IA32_UMWAIT_CONTROL MSR register. > > By default, C0.2 is enabled and the user wait instructions result in > lower power consumption with slower wakeup time. > > But in real time systems which require faster wakeup time although power > savings could be smaller, the administrator needs to disable C0.2 and all > C0.2 requests from user applications revert to C0.1. > > A sysfs interface "/sys/devices/system/cpu/umwait_control/enable_c02" is > created to allow the administrator to control C0.2 state during run time. This looks better than the previous version. I think the locking is still rather confused. You have a mutex that you hold while changing the value, which is entirely reasonable. But, of the code paths that write the MSR, only one takes the mutex. I think you should consider making a function that just does: wrmsr(MSR_IA32_UMWAIT_CONTROL, READ_ONCE(umwait_control_cached), 0); and using it in all the places that update the MSR. The only thing that should need the lock is the sysfs code to avoid accidentally corrupting the value, but that code should also use WRITE_ONCE to do its update.