From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753343AbcD0Jzl (ORCPT ); Wed, 27 Apr 2016 05:55:41 -0400 Received: from sci-ig4.spreadtrum.com ([114.30.40.213]:10356 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752815AbcD0Jzj convert rfc822-to-8bit (ORCPT ); Wed, 27 Apr 2016 05:55:39 -0400 From: "Gaurav Jindal (Gaurav Jindal)" To: "mingo@redhat.com" , "peterz@infradead.com" CC: "linux-kernel@vger.kernel.org" Subject: [PATCH]sched: cpuidle: Do not fetch current cpu in loop in idle thread Thread-Topic: [PATCH]sched: cpuidle: Do not fetch current cpu in loop in idle thread Thread-Index: AQHRoGrRyFuNOi6VE0WzoMIkO71DxQ== Date: Wed, 27 Apr 2016 09:54:41 +0000 Message-ID: <20160427095434.GD877@gauravjindalubtnb.del.spreadtrum.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.1.200] Content-Type: text/plain; charset="us-ascii" Content-ID: <451E790E2DBE124792A2D50BB9FAC1AB@spreadtrum.com> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-MAIL: SHSQR01.spreadtrum.com u3R9ssdF040981 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently in idle thread loop, smp_processor_id() fetches the cpu id every time it runs thus taking more cpu cycles. Instead, save the cpu id as local varaible while entering the idle thread and use it in the loop. Since it is local variable, it will be correct for each core. It will also save cycles consumed while fetching cpu id using smp_proceesor_id() in loop. Patch: ------------------------------------------------------------------------------ diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 1214f0a..9696f9e 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -185,6 +185,9 @@ exit_idle: */ static void cpu_idle_loop(void) { + int cpu_id; + + cpu_id = smp_processor_id(); while(1) { /* *If the arch has a polling bit, we maintain an invariant: @@ -202,7 +205,7 @@ static void cpu_idle_loop(void) check_pgt_cache(); rmb(); - if (cpu_is_offline(smp_processor_id())) + if(cpu_is_offline(cpu_id)) arch_cpu_idle_dead(); local_irq_disable(); ------------------------------------------------------------------------------ Signed-off-by: Gaurav Jindal Regards Gaurav Jindal