Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753161AbdGFXdp (ORCPT ); Thu, 6 Jul 2017 19:33:45 -0400 Received: from mga11.intel.com ([192.55.52.93]:23522 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752575AbdGFXdo (ORCPT ); Thu, 6 Jul 2017 19:33:44 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,319,1496127600"; d="scan'208";a="1148780202" Date: Thu, 6 Jul 2017 16:35:17 -0700 (PDT) From: Shivappa Vikas X-X-Sender: vikas@vshiva-Udesk To: Thomas Gleixner cc: Vikas Shivappa , x86@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, peterz@infradead.org, ravi.v.shankar@intel.com, vikas.shivappa@intel.com, tony.luck@intel.com, fenghua.yu@intel.com, andi.kleen@intel.com Subject: Re: [PATCH 17/21] x86/intel_rdt/cqm: Add sched_in support In-Reply-To: Message-ID: References: <1498503368-20173-1-git-send-email-vikas.shivappa@linux.intel.com> <1498503368-20173-18-git-send-email-vikas.shivappa@linux.intel.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2496 Lines: 89 On Sun, 2 Jul 2017, Thomas Gleixner wrote: > On Mon, 26 Jun 2017, Vikas Shivappa wrote: >> DECLARE_PER_CPU(struct intel_pqr_state, pqr_state); >> DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid); >> +DECLARE_PER_CPU_READ_MOSTLY(int, cpu_rmid); >> DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); >> +DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key); >> +DECLARE_STATIC_KEY_FALSE(rdt_enable_key); > > Please make this a two stage change. Add rdt_enable_key first and then the > monitoring stuff. Ideally you introduce rdt_enable_key here and in the > control code in one go. > >> +static void __intel_rdt_sched_in(void) >> { >> - if (static_branch_likely(&rdt_alloc_enable_key)) { >> - struct intel_pqr_state *state = this_cpu_ptr(&pqr_state); >> - int closid; >> + struct intel_pqr_state *state = this_cpu_ptr(&pqr_state); >> + u32 closid = 0; >> + u32 rmid = 0; >> >> + if (static_branch_likely(&rdt_alloc_enable_key)) { >> /* >> * If this task has a closid assigned, use it. >> * Else use the closid assigned to this cpu. >> @@ -55,14 +59,31 @@ static inline void intel_rdt_sched_in(void) >> closid = current->closid; >> if (closid == 0) >> closid = this_cpu_read(cpu_closid); >> + } >> + >> + if (static_branch_likely(&rdt_mon_enable_key)) { >> + /* >> + * If this task has a rmid assigned, use it. >> + * Else use the rmid assigned to this cpu. >> + */ >> + rmid = current->rmid; >> + if (rmid == 0) >> + rmid = this_cpu_read(cpu_rmid); >> + } >> >> - if (closid != state->closid) { >> - state->closid = closid; >> - wrmsr(IA32_PQR_ASSOC, state->rmid, closid); >> - } >> + if (closid != state->closid || rmid != state->rmid) { >> + state->closid = closid; >> + state->rmid = rmid; >> + wrmsr(IA32_PQR_ASSOC, rmid, closid); > > This can be written smarter. > > struct intel_pqr_state newstate = this_cpu_read(rdt_cpu_default); > struct intel_pqr_state *curstate = this_cpu_ptr(&pqr_state); > > if (static_branch_likely(&rdt_alloc_enable_key)) { > if (current->closid) > newstate.closid = current->closid; > } > > if (static_branch_likely(&rdt_mon_enable_key)) { > if (current->rmid) > newstate.rmid = current->rmid; > } > > if (newstate != *curstate) { > *curstate = newstate; > wrmsr(IA32_PQR_ASSOC, newstate.rmid, newstate.closid); > } > > The unconditional read of rdt_cpu_default is the right thing to do because > the default behaviour is exactly this. Ok makes sense. Will fix. Thanks, Vikas > > Thanks, > > tglx > > > >