Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3665497ioa; Tue, 26 Apr 2022 07:50:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTCCZmPCVZ7eb7w5YdH1EXKIY9qEnNbUQ/WsyhRhNT1sBYtXfll9fjUxOEGrlRUkkWdmOb X-Received: by 2002:a05:6a00:278d:b0:50d:5320:9ef4 with SMTP id bd13-20020a056a00278d00b0050d53209ef4mr4973884pfb.50.1650984630018; Tue, 26 Apr 2022 07:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650984630; cv=none; d=google.com; s=arc-20160816; b=YOIUHGkveIiFYvrp4aEJq94Hn+u6UDHAHmKSXji1LhgiZzwyUtkv4tfCTCuwK3VJgx AuPcH2GX7958L2MPnwDHEpD3+Bp8V1+M6NnP7iqNybMkidzYhxu90zdqE+O7d4eQjciM i/mzoV73qygZO89H+w4j6gdrxSTEEOFpELL/VaM0WFvy69mAjlVHDncAzULU6JOWxqQl XQD3Erwc8ztoe3xVO21fIWTDeKyIS8wi70yV/SyzVpxOPh7KyLZ7TJK9EQCe/6hOZ+9A bhVjNbmRa7GoOqXDL9OuOtXMXxMCpBlmuatIHGyJEMMyJOpDdp5dcXsMJIVi0c5g9p3D 8zHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=MMZh3TWkXRwRnAev3/RS+MNFF9k12kNd00lFq0Z4NTE=; b=mr/1bXZNG/th2TM7Wc/qI3o5m1xnjXtS6CUl9ad2LWUkrglvWc+0WZkEasuRaC3R5w oDiRGj5HQUwtWxf1fNcSOOtbb1XKyXIJaRNgWLriIHZTicwvUwDe+7rpLn1lym+dxpDg zUT26bUjU81CH2FKhVBpqe9zj553FxGqu+V7PAIjoJ7k4KjUEg+ZzdRW6Mv2gAMRKwmK 1+JO7kN6NFQq7kegvOxrnPN8IVsErpFSc/NMxMkZ05hZXjqOwuOv8acG1W5+OBsnrouP veT/xtXYDTOB95FvDjL4RSPewDsHHJHotX7Xnc87lXVF5YMYPLYqjKOqX/j0e72n2Any fG9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=jA0m+LEK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a170902708500b00158951ab217si18450269plk.342.2022.04.26.07.50.09; Tue, 26 Apr 2022 07:50:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=jA0m+LEK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243963AbiDYUyD (ORCPT + 99 others); Mon, 25 Apr 2022 16:54:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbiDYUyC (ORCPT ); Mon, 25 Apr 2022 16:54:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC409344C4 for ; Mon, 25 Apr 2022 13:50:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 600CFB81A7C for ; Mon, 25 Apr 2022 20:50:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB334C385A7; Mon, 25 Apr 2022 20:50:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1650919854; bh=Pg3eLCwKekjT5FX2gXoHyMivtK4TghxUHiirEWzcWtU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jA0m+LEKBIGbI7aEXyYUSX7V8tXhzPXtlziXqElnOowIoUGdbPpIZ6fF8EbjgEOxC GhcyFU8xARrii6u121uHjzf8iU7YG1cKw3UvG/Sospsy4B1OUiB/C4siEWeMnd09hl CtNV3aNdjiVRlSB+JmG/LeYZ1lNCWSRn2ZMd5oy8= Date: Mon, 25 Apr 2022 13:50:53 -0700 From: Andrew Morton To: Prakash Sangappa Cc: LKML , Thomas Gleixner , Peter Zijlstra , Davidlohr Bueso , Manfred Spraul Subject: Re: [PATCH] ipc: Update semtimedop() to use hrtimer Message-Id: <20220425135053.a74082b68d26f4f3f0344500@linux-foundation.org> In-Reply-To: <8603345D-9AAD-43FF-B1DF-941BDA799DF5@oracle.com> References: <1650333099-27214-1-git-send-email-prakash.sangappa@oracle.com> <8603345D-9AAD-43FF-B1DF-941BDA799DF5@oracle.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Apr 2022 19:38:44 +0000 Prakash Sangappa wrote: > > > > On Apr 18, 2022, at 6:51 PM, Prakash Sangappa wrote: > > > > semtimedop() should be converted to use hrtimer like it has been > > done for most of the system calls with timeouts. This system call > > already takes a struct timespec as an argument and can therefore > > provide finer granularity timed wait. > > > > Signed-off-by: Prakash Sangappa > > Can I get a review of this patch? That would be nice. I looked at it, seemed OK. Perhaps the usual IPC developers (Davidlohr and Manfred) can comment? > Note this patch has been added to Andrew's mm tree. > > > > --- > > ipc/sem.c | 15 +++++++++++---- > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > diff --git a/ipc/sem.c b/ipc/sem.c > > index 0dbdb98..6cd1a1b8 100644 > > --- a/ipc/sem.c > > +++ b/ipc/sem.c > > @@ -1995,7 +1995,10 @@ long __do_semtimedop(int semid, struct sembuf *sops, > > int max, locknum; > > bool undos = false, alter = false, dupsop = false; > > struct sem_queue queue; > > - unsigned long dup = 0, jiffies_left = 0; > > + unsigned long dup = 0; > > + ktime_t expires; > > + int timed_out = 0; > > + struct timespec64 end_time; > > > > if (nsops < 1 || semid < 0) > > return -EINVAL; > > @@ -2008,7 +2011,9 @@ long __do_semtimedop(int semid, struct sembuf *sops, > > error = -EINVAL; > > goto out; > > } > > - jiffies_left = timespec64_to_jiffies(timeout); > > + ktime_get_ts64(&end_time); > > + end_time = timespec64_add_safe(end_time, *timeout); > > + expires = timespec64_to_ktime(end_time); > > } > > > > > > @@ -2167,7 +2172,9 @@ long __do_semtimedop(int semid, struct sembuf *sops, > > rcu_read_unlock(); > > > > if (timeout) > > - jiffies_left = schedule_timeout(jiffies_left); > > + timed_out = !schedule_hrtimeout_range(&expires, > > + current->timer_slack_ns, > > + HRTIMER_MODE_ABS); > > else > > schedule(); > > > > @@ -2210,7 +2217,7 @@ long __do_semtimedop(int semid, struct sembuf *sops, > > /* > > * If an interrupt occurred we have to clean up the queue. > > */ > > - if (timeout && jiffies_left == 0) > > + if (timeout && timed_out) > > error = -EAGAIN; > > } while (error == -EINTR && !signal_pending(current)); /* spurious */ > > > > -- > > 2.7.4 > > >