Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp456692imu; Thu, 3 Jan 2019 00:48:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN47QN4T5SZssIgwhRGzAuwi4FZVfJPdaalrEwX4seOLQ/sKtZTnG7vd0XCr94mOQB/AT/By X-Received: by 2002:a62:31c1:: with SMTP id x184mr48702368pfx.204.1546505320891; Thu, 03 Jan 2019 00:48:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546505320; cv=none; d=google.com; s=arc-20160816; b=0xgeI0sJhypkjwFxzB7CL6TtX0R89Ak9vup2mSlwY/bJpN/1AZ5kyFqGo45tNfY3J3 Lv75pLu8d3+OEfFcHQRMIJ1G7nMe1GfIpHechQILPNYE+YgNx5IjI5ulqF5ZW07qDw9O HEv8e2iACJSjrCEsROmhxjGxOm0bl9TR2Yi3baaNteCwrXYz384/JnS8VPMxfDu3lv6D 7JZoTdYTXnZFt/jY4jZNnvbNmVhOgnNXuaQfIneCxjUa5RyteAb0FVnA/ahU4jXlR+Ph oSIrb2FVe48tsOKnUJ+yrURHXp4ABeZTNU15hqw+SvEoK+vtzGleJHYrYLldqy3PR8Wi qgbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=uy4Yldj6lbTTbDINFbGwdZD0vJ855sleFOdgC7zx/bw=; b=WiV2ti3SgiW5AH+Z/X2rQeSjviBNAoNfxG9na9vpb1H/nyUJtkpXmGLtp7CpNYX1Kf HVnpVgplnAUc2gq2WA2VOBMXzzcjNMKMEAkgDx2giV45hJjmzSPyrbNamAszJYA+KID+ 13JcQWvHvy52z+2twIJsP9Pscj4JPlgtAEzegTzl73wM0Gc337slUm3SCfj42V3IbPl8 afX7gLDPcvgob88rAPHi1Oti/kHs8GeCL7LJulHM0gG91MeV4IL1qnl3cXiPkqm38+Xo 1sywNbcLL2M3Mu/wgDCP1tegWi95H6Xc3TIp4b1OCXRW3sHJuQKmj1G1RvUP+GZxInv7 I09g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e69si946326pfg.137.2019.01.03.00.48.25; Thu, 03 Jan 2019 00:48:40 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728605AbfACDx2 (ORCPT + 99 others); Wed, 2 Jan 2019 22:53:28 -0500 Received: from 59-120-53-16.HINET-IP.hinet.net ([59.120.53.16]:43485 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726136AbfACDx2 (ORCPT ); Wed, 2 Jan 2019 22:53:28 -0500 X-Greylist: delayed 1224 seconds by postgrey-1.27 at vger.kernel.org; Wed, 02 Jan 2019 22:53:27 EST Received: from ATCSQR.andestech.com (localhost [127.0.0.2] (may be forged)) by ATCSQR.andestech.com with ESMTP id x033al6P020432; Thu, 3 Jan 2019 11:36:47 +0800 (GMT-8) (envelope-from vincentc@andestech.com) Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id x033aQWw020403; Thu, 3 Jan 2019 11:36:26 +0800 (GMT-8) (envelope-from vincentc@andestech.com) Received: from atcsqa06.andestech.com (10.0.15.65) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Thu, 3 Jan 2019 11:32:40 +0800 From: Vincent Chen To: , , , , , CC: Vincent Chen Subject: [PATCH] RISC-V: Add _TIF_NEED_RESCHED check for kernel thread when CONFIG_PREEMPT=y Date: Thu, 3 Jan 2019 11:32:33 +0800 Message-ID: <1546486353-23115-1-git-send-email-vincentc@andestech.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.15.65] X-DNSRBL: X-MAIL: ATCSQR.andestech.com x033aQWw020403 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cond_resched() can be used to yield the CPU resource if CONFIG_PREEMPT is not defined. Otherwise, cond_resched() is a dummy function. In order to avoid kernel thread occupying entire CPU, when CONFIG_PREEMPT=y, the kernel thread needs to follow the rescheduling mechanism like a user thread. Signed-off-by: Vincent Chen --- arch/riscv/kernel/asm-offsets.c | 1 + arch/riscv/kernel/entry.S | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletions(-) diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c index 6a92a2f..dac9834 100644 --- a/arch/riscv/kernel/asm-offsets.c +++ b/arch/riscv/kernel/asm-offsets.c @@ -39,6 +39,7 @@ void asm_offsets(void) OFFSET(TASK_STACK, task_struct, stack); OFFSET(TASK_TI, task_struct, thread_info); OFFSET(TASK_TI_FLAGS, task_struct, thread_info.flags); + OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count); OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp); OFFSET(TASK_TI_USER_SP, task_struct, thread_info.user_sp); OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu); diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 13d4826..728b72d 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -144,6 +144,10 @@ _save_context: REG_L x2, PT_SP(sp) .endm +#if !IS_ENABLED(CONFIG_PREEMPT) +#define resume_kernel restore_all +#endif + ENTRY(handle_exception) SAVE_ALL @@ -228,7 +232,7 @@ ret_from_exception: REG_L s0, PT_SSTATUS(sp) csrc sstatus, SR_SIE andi s0, s0, SR_SPP - bnez s0, restore_all + bnez s0, resume_kernel resume_userspace: /* Interrupts must be disabled here so flags are checked atomically */ @@ -250,6 +254,18 @@ restore_all: RESTORE_ALL sret +#if IS_ENABLED(CONFIG_PREEMPT) +resume_kernel: + REG_L s0, TASK_TI_PREEMPT_COUNT(tp) + bnez s0, restore_all +need_resched: + REG_L s0, TASK_TI_FLAGS(tp) + andi s0, s0, _TIF_NEED_RESCHED + beqz s0, restore_all + call preempt_schedule_irq + j need_resched +#endif + work_pending: /* Enter slow path for supplementary processing */ la ra, ret_from_exception -- 1.7.1