From patchwork Sun Aug 9 01:48:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhilash Jindal X-Patchwork-Id: 6982021 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CF90DC05AC for ; Mon, 10 Aug 2015 10:10:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E45632078B for ; Mon, 10 Aug 2015 10:10:41 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 7718320769 for ; Mon, 10 Aug 2015 10:10:40 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 7C615265881; Mon, 10 Aug 2015 12:10:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id AC31B264F45; Mon, 10 Aug 2015 12:10:00 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 824042608D3; Sun, 9 Aug 2015 03:48:31 +0200 (CEST) Received: from mail-io0-f175.google.com (mail-io0-f175.google.com [209.85.223.175]) by alsa0.perex.cz (Postfix) with ESMTP id 7876D26084B for ; Sun, 9 Aug 2015 03:48:24 +0200 (CEST) Received: by ioii16 with SMTP id i16so142199038ioi.0 for ; Sat, 08 Aug 2015 18:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=w0m32LnLH8viZqQMSqoxd44qPTE1nppysfVoWoYfPGk=; b=iuhn7nprPeXvWqFY6gk+ri25eSMzkqPGXzdcOXt+QCGFLcx4oR1HNfk4ftDEQIT+Hj azAdDTylFB4SXQBm8D7zm2wKG0D6kSeBy4JgCy+d/1HTvd41Hj4+2XPUcpECIyYEZEER d3hiF3IJrvynxJ4r1MORyY64ZlKUkUKJLrD7KGHHy9NEaF1wylhgtb0AOB1SozRUjLUF h+y8ElWBnEQyypuzlsXb+yiZ3PDFMgTTIb835/DaUFzo82lfv2IXYgXTuAqUI+Ci6Wxn g9E84R4sfojRwB8XBqk1+tLKftJ/6F/lYULjvZxKqKD7rizOjB/0aUQgmMvtXxxQZDx7 adwQ== MIME-Version: 1.0 X-Received: by 10.107.14.10 with SMTP id 10mr14258974ioo.45.1439084903157; Sat, 08 Aug 2015 18:48:23 -0700 (PDT) Received: by 10.79.5.84 with HTTP; Sat, 8 Aug 2015 18:48:23 -0700 (PDT) Date: Sat, 8 Aug 2015 21:48:23 -0400 Message-ID: From: Abhilash Jindal To: alsa-devel@alsa-project.org X-Mailman-Approved-At: Mon, 10 Aug 2015 12:09:57 +0200 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: tiwai@suse.de Subject: [alsa-devel] ALSA: es1968: Use monotonic clock X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Wall time obtained from do_gettimeofday is susceptible to sudden jumps due to user setting the time or due to NTP. Monotonic time is constantly increasing time better suited for comparing two timestamps. --- sound/pci/es1968.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) chip->in_measurement = 0; @@ -1776,11 +1776,11 @@ static void es1968_measure_clock(struct es1968 *chip) offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2); t = stop_time.tv_sec - start_time.tv_sec; - t *= 1000000; - if (stop_time.tv_usec < start_time.tv_usec) - t -= start_time.tv_usec - stop_time.tv_usec; + t *= USEC_PER_SEC; + if (stop_time.tv_nsec < start_time.tv_nsec) + t -= (start_time.tv_nsec - stop_time.tv_nsec)/NSEC_PER_USEC; else - t += stop_time.tv_usec - start_time.tv_usec; + t += (stop_time.tv_nsec - start_time.tv_nsec)/NSEC_PER_USEC; if (t == 0) { snd_printk(KERN_ERR "?? calculation error..\n"); } else { diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c index b0e3d92..6830c31 100644 --- a/sound/pci/es1968.c +++ b/sound/pci/es1968.c @@ -1710,7 +1710,7 @@ static void es1968_measure_clock(struct es1968 *chip) int i, apu; unsigned int pa, offset, t; struct esm_memory *memory; - struct timeval start_time, stop_time; + struct timespec start_time, stop_time; if (chip->clock == 0) chip->clock = 48000; /* default clock value */ @@ -1759,12 +1759,12 @@ static void es1968_measure_clock(struct es1968 *chip) snd_es1968_bob_inc(chip, ESM_BOB_FREQ); __apu_set_register(chip, apu, 5, pa & 0xffff); snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR); - do_gettimeofday(&start_time); + ktime_get_ts(&start_time); spin_unlock_irq(&chip->reg_lock); msleep(50); spin_lock_irq(&chip->reg_lock); offset = __apu_get_register(chip, apu, 5); - do_gettimeofday(&stop_time); + ktime_get_ts(&stop_time); snd_es1968_trigger_apu(chip, apu, 0); /* stop */ snd_es1968_bob_dec(chip);