From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752021AbcFZGmq (ORCPT ); Sun, 26 Jun 2016 02:42:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39761 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751630AbcFZGmb (ORCPT ); Sun, 26 Jun 2016 02:42:31 -0400 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: xinhui.pan@linux.vnet.ibm.com From: Pan Xinhui To: linux-kernel@vger.kernel.org Cc: peterz@infradead.org, mingo@redhat.com, boqun.feng@gmail.com, pan xinhui Subject: [PATCH 1/2] kernel/sched: introduce vcpu preempted interface Date: Sun, 26 Jun 2016 06:41:54 -0400 X-Mailer: git-send-email 2.4.11 In-Reply-To: <1466937715-6683-1-git-send-email-xinhui.pan@linux.vnet.ibm.com> References: <1466937715-6683-1-git-send-email-xinhui.pan@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062606-8235-0000-0000-000008ABF511 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062606-8236-0000-0000-000032922999 Message-Id: <1466937715-6683-2-git-send-email-xinhui.pan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-06-26_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606260074 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: pan xinhui this supports to fix lock holder preempted issue which run as a guest two interfaces, bool vcpu_is_preempted(int cpu); unsigned int vcpu_get_yield_count(int cpu); arch may need implement anyone of them. some spinneris may also need call need_yield_to(int cpu, unsigned int old_yield_count) to know if it need stop the spinning. Signed-off-by: Pan Xinhui --- include/linux/sched.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 6e42ada..9c565d2 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -3293,6 +3293,40 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) #endif /* CONFIG_SMP */ +#ifdef arch_vcpu_is_preempted +static inline bool vcpu_is_preempted(int cpu) +{ + return arch_vcpu_is_preempted(cpu); +} +#else +static inline bool vcpu_is_preempted(int cpu) +{ + return 0; +} +#endif + +#ifdef arch_vcpu_get_yield_count +static inline unsigned int vcpu_get_yield_count(int cpu) +{ + return arch_vcpu_get_yield_count(cpu); +} +#else +static inline unsigned int vcpu_get_yield_count(int cpu) +{ + return 0; +} +#endif + +static inline bool +need_yield_to(int vcpu, unsigned int old_yield_count) +{ + /* if we find the vcpu is preempted, + * then we may want to kick it, IOW, yield to it + */ + return vcpu_is_preempted(vcpu) || + (vcpu_get_yield_count(vcpu) != old_yield_count); +} + extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask); extern long sched_getaffinity(pid_t pid, struct cpumask *mask); -- 2.4.11