From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753873AbcHRMAw (ORCPT ); Thu, 18 Aug 2016 08:00:52 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:44622 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751442AbcHRMAv (ORCPT ); Thu, 18 Aug 2016 08:00:51 -0400 Date: Thu, 18 Aug 2016 13:28:26 +0200 From: Peter Zijlstra To: Colin Vidal Cc: linux-kernel@vger.kernel.org, mingo@redhat.com Subject: Re: sched: current instead rq->current Message-ID: <20160818112825.GB10153@twins.programming.kicks-ass.net> References: <1471289435.8946.28.camel@cvidal.org> <1471462781.2204.5.camel@cvidal.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1471462781.2204.5.camel@cvidal.org> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 17, 2016 at 09:39:41PM +0200, Colin Vidal wrote: > On Mon, 2016-08-15 at 21:30 +0200, Colin Vidal wrote: > > Hello, > > > > At the beginning of __schedule (kernel/sched/core.c), the current > > task > > is get with rq->curr. I try to to understand why not directly using > > current instead? > > -       int cpu; > >   > > -       cpu = smp_processor_id(); > > -       rq = cpu_rq(cpu); > > -       prev = rq->curr; > > +       rq = cpu_rq(smp_processor_id()); > > +       prev = current; > > > > and it seems to work (only tested on x86-64), but... To simple? its more expensive, rq->curr is a simple dereference (and we need that cacheline anyway), while current is a weird macro that expands to potentially a lot of code, depending on the arch.