Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp20921imm; Thu, 4 Oct 2018 14:47:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV63NFuxQcipxihzcUeyjDf+iceq6fg3/WBmkEoMlVNRPMZG5JHE+93IXWT+DH3+sdusuEvFB X-Received: by 2002:a62:3a43:: with SMTP id h64-v6mr8649355pfa.119.1538689658111; Thu, 04 Oct 2018 14:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538689658; cv=none; d=google.com; s=arc-20160816; b=CjztFsGYs1+gfB8jRiix14roIkBHYaumuJVv1Mdb0nqtfchbQbEktYl5esOJeBb2QC EwB4GiejPJ2OsomWC6P45BCjE5vYBev1A9xjCVMy8kxmxiBvx/fEA/T3uIQTvRNH+7Zh 6aHjAJo22WPXIkZ7ksKjh7nuXXgeWCL2s67w5ac+TeXvMuYDWFl/Mqgi52+302Dj7HpA P/WYyHR2fHix3KeyJzICr1DBwuKLywycJMygYdHUtxikLZy9Yc1QBRubUqLKkTn9NFi0 j0hHN3zOqKpJSQ/drCj9yC3yMX4X+oukLV5CXMF1KI3bbNonDQOm5YBUX9Gb+uw6FCp7 cMdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=+hqDq16HJeeC2zm4wN3Kamu/VnL1pPHNzT5xauUleJs=; b=iIlUyacXHfmiCDAeiV9bh9PHW/WMq1guzRkUDwDMokvSmW7U1UyKnfRJLZtFM4ZFia //rLx1s3sjJupWC3XrBPUyClK5J7PcT15jqauvWl6svxgsKGhQlfR3OSlEx44SfSt8GS IQ8MFGTqW0udQEY7a2J2DlkkwCvpLh215bIKui8KVxE8qd2qRJyzQaWqULQdQ1yBhl55 b8RPDI6bzMD5W1wlDo/EOMLYMl8BiEGEFfqlyOJPcvukWwCSZGfnJILE5hi0Lnufp4mF DhOXoAnw8tSFZxoAMMJTUdEmvFSXr2/HyTzM3dIu6eyX2lfzs8X1dCMMdoNZ04FstHVQ 6oAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PC2g+B2q; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q27-v6si6595920pfd.285.2018.10.04.14.47.23; Thu, 04 Oct 2018 14:47:38 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=PC2g+B2q; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727941AbeJEEke (ORCPT + 99 others); Fri, 5 Oct 2018 00:40:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:38774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726570AbeJEEkd (ORCPT ); Fri, 5 Oct 2018 00:40:33 -0400 Received: from localhost (unknown [198.217.64.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 656F32084D; Thu, 4 Oct 2018 21:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1538689515; bh=mQBzNNO4z/XWBj1Ua6nrwvXNMEsH6cSabZ5p6i2MJ8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=PC2g+B2qaYLLgz7T8fprMLxmEjKOH02+lO9YSQnMXzyE5Cw56yl95KwIwMrDuA2xn kP+Zts2Qdnav7+yMK6j/bEYEzrZ2+ln6P47kaB6djHckjH9pUkq5zEjzTkDLFaY37H Sh6P91PgFwdg22np9KQcg+Vl6snS3vvVmSjM91eM= From: Andy Lutomirski To: x86@kernel.org Cc: LKML , Andy Lutomirski Subject: [PATCH 2/3] x86/vdso: Rearrange do_hres() to improve code generation Date: Thu, 4 Oct 2018 14:44:44 -0700 Message-Id: <99e93a6be59916959ad259482f4cf347e8af9bac.1538689401.git.luto@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vgetcyc() is full of barriers, so fetching values out of the vvar page before vgetcyc() for use after vgetcyc() results in poor code generation. Put vgetcyc() first to avoid this problem. Also, pull the tv_sec division into the loop and put all the ts writes together. The old code wrote ts->tv_sec on each iteration before the syscall fallback check and then added in the offset afterwards, which forced the compiler to pointlessly copy base->sec to ts->tv_sec on each iteration. The new version seems to generate sensible code. Saves several cycles. With this patch applied, the result is faster than before the clock_gettime() rewrite. Signed-off-by: Andy Lutomirski --- arch/x86/entry/vdso/vclock_gettime.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c index 18c8a78d1ec9..419de7552c2f 100644 --- a/arch/x86/entry/vdso/vclock_gettime.c +++ b/arch/x86/entry/vdso/vclock_gettime.c @@ -147,10 +147,9 @@ notrace static int do_hres(clockid_t clk, struct timespec *ts) do { seq = gtod_read_begin(gtod); - ts->tv_sec = base->sec; + cycles = vgetcyc(gtod->vclock_mode); ns = base->nsec; last = gtod->cycle_last; - cycles = vgetcyc(gtod->vclock_mode); if (unlikely((s64)cycles < 0)) return vdso_fallback_gettime(clk, ts); if (cycles > last) @@ -158,7 +157,7 @@ notrace static int do_hres(clockid_t clk, struct timespec *ts) ns >>= gtod->shift; } while (unlikely(gtod_read_retry(gtod, seq))); - ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); + ts->tv_sec = base->sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); ts->tv_nsec = ns; return 0; -- 2.17.1