Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2858592yba; Mon, 6 May 2019 12:43:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsX082b1Ce/yk3Y4+EEqCazTsJKBpvZw4kTTA68zI3q5JJgeXvzOLie9GviHvIq1qgGGGq X-Received: by 2002:a63:4ce:: with SMTP id 197mr34772939pge.309.1557171838960; Mon, 06 May 2019 12:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557171838; cv=none; d=google.com; s=arc-20160816; b=ZoMdBel6aF2E7+BGbWsi2CT/mZEHpZ7cO25Ou5gAlQa68NIto8L2ZUMp3Ed1Obq23u iOfimNKQb57ylZR2JnZtQCmxw/wPoEutUeYWnBP6ULQzbByok/LbTgq8p0tS3XUCEdK1 4TnEAfYlA6uMB1TNjBKqFGQtAtSZhSQVtIyyz4Jaz3DxfUWLtoSWAUzzwTfDCjSM7Tca c/8iyD5iV67OYdwXIcMu5D42CMdKXt/j71oP73LOsZn5lUsD0o2Lr1cKAiSNO+Pr3oXA iw6s2bslcLv2nOau7WetbnGIvoY8DzPA8orppOncFJi3viaa3p+CZREOo4oQuUZcZen2 Auow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0ammkuem5ljW29XFg6gnlxzG9/SZy+QwUoJ7xJbCSXI=; b=w9KJON8WEPnp9pPqX0zcLcorkVTpcvM0q3tHyzz5/8qU8tHRJ1Q45v10S5ZMScytNy oKD9IJRZx6UQb6RGvMN7SP9XsSCV3LscDbmOYpndJ8n0XDG+ms36eghaa9OBKnUeQLpS ZJtbgTTlD0xoryKH2sjMH8f1dcm87me4qsfWymcVG4I0xw/0hCTuJo2WVGu6hfFUgt/1 XNUZ4G2PHxU1j3Mh7HyRzBdhfL3pwMFw2JczKiX94YnA+WvWG/VUFhrZsFp+CGQfJy0m 5m8fU2xU5LHPHZ2o4ANHjSkZVEvg4A0bM49iHd3c8rC5KtcMdf/WF6hk6CY5cp1obzhP pZZw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cd5si6105221plb.207.2019.05.06.12.43.42; Mon, 06 May 2019 12:43:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726409AbfEFTks (ORCPT + 99 others); Mon, 6 May 2019 15:40:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33632 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726145AbfEFTkr (ORCPT ); Mon, 6 May 2019 15:40:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60588300744C for ; Mon, 6 May 2019 19:40:47 +0000 (UTC) Received: from torg.redhat.com (ovpn-120-147.rdu2.redhat.com [10.10.120.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0034460C43; Mon, 6 May 2019 19:40:46 +0000 (UTC) From: Clark Williams To: John Kacur Cc: linux-kernel@vger.kernel.org Subject: [PATCH] hwlatdetect: disable/enable c-state transitions during detection Date: Mon, 6 May 2019 14:40:46 -0500 Message-Id: <20190506194046.13144-1-williams@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 06 May 2019 19:40:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Recent performance tuning problems led me to realize that just running at fifo:99 and turning off interrupts isn't enough while looking for BIOS induced latencies. Power savings logic is built into most modern cpus and so must be disabled while looking for BIOS induced (SMI/NMI) latencies. Use the /dev/cpu_dma_latency mechanism to disable c-state transitions while running the hardware latency detector. Open the file /dev/cpu_dma_latency and write a 32-bit zero to it, which will prevent c-state transitions while the file is open. Signed-off-by: Clark Williams --- src/hwlatdetect/hwlatdetect.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py index 2c8f9f160419..368079a158b1 100755 --- a/src/hwlatdetect/hwlatdetect.py +++ b/src/hwlatdetect/hwlatdetect.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -# (C) 2018 Clark Williams +# (C) 2018,2019 Clark Williams # (C) 2015,2016 Clark Williams # (C) 2009 Clark Williams # @@ -213,6 +213,22 @@ watch = False counts = [ int(x.strip()) for x in p.stdout.readlines()] return counts + # methods for preventing/enabling c-state transitions + # openinging /dev/cpu_dma_latency and writeing a 32-bit zero to that file will prevent + # c-state transitions while the file descriptor is open. + # use c_states_off() to disable c-state transitions + # use c_states_on() to close the file descriptor and re-enable c-states + # + def c_states_off(self): + self.dma_latency_handle = os.open("/dev/cpu_dma_latency", os.O_WRONLY) + os.write(self.dma_latency_handle, b'\x00\x00\x00\x00') + debug("c-states disabled") + + def c_states_on(self): + if self.dma_latency_handle: + os.close(self.dma_latency_handle) + debug("c-states enabled") + def cleanup(self): raise RuntimeError("must override base method 'cleanup'!") @@ -235,6 +251,7 @@ watch = False def start(self): count = 0 threshold = int(self.get("threshold")) + self.c_states_off() debug("enabling detector module (threshold: %d)" % threshold) self.set("enable", 1) while self.get("enable") == 0: @@ -258,6 +275,7 @@ watch = False time.sleep(0.1) debug("retrying disable of detector module(%d)" % count) self.set("enable", 0) + self.c_states_on() debug("detector module disabled") def detect(self): -- 2.21.0