From patchwork Wed Nov 14 20:43:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 1744031 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A48B63FCF7 for ; Wed, 14 Nov 2012 20:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932145Ab2KNUol (ORCPT ); Wed, 14 Nov 2012 15:44:41 -0500 Received: from mail-qc0-f174.google.com ([209.85.216.174]:46838 "EHLO mail-qc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423338Ab2KNUnj (ORCPT ); Wed, 14 Nov 2012 15:43:39 -0500 Received: by mail-qc0-f174.google.com with SMTP id o22so558292qcr.19 for ; Wed, 14 Nov 2012 12:43:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:reply-to:organization; bh=/Q5wtPCwFec6BO4LlC/Y52CqdWL2+YvqBCdwru64ap8=; b=SBuDOEe40yrInT5WI6nfQmdr3hp76OOw191BnqQ0I7UbrDkDspKQI1GIU8hPWR4kAE 618V1BEhl09vKXSJ//eZEx1iUgK5Wj0qgBjMy6rYTCf+h9So/aCaQXi5gZ5Sa3Azv7dk HchQZgJcN30fqUWQtFRsvTlgsxWfroVQ/RpLg/OdWKA2mZ9R6/1lWEHn8v1NDEmXqbLO 3miq5YSdFFCcrN+bZ4vjTshKrJJv2dMbFpvjtdM8P829AgCxnC9kvxi/FApkQvQxymeR LcQunePv7XIFq9UlkhdXySEOiP5I9lTbk/Sv2WwVUNf54t5NaAHgfMaiuuW3NcXot0h6 KnvQ== Received: by 10.224.72.206 with SMTP id n14mr26859868qaj.38.1352925818561; Wed, 14 Nov 2012 12:43:38 -0800 (PST) Received: from x980.localdomain6 ([173.48.76.143]) by mx.google.com with ESMTPS id f3sm3314272qaj.7.2012.11.14.12.43.37 (version=SSLv3 cipher=OTHER); Wed, 14 Nov 2012 12:43:38 -0800 (PST) From: Len Brown To: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Len Brown Subject: [PATCH 6/7] tools/power turbostat: prevent infinite loop on migration error path Date: Wed, 14 Nov 2012 15:43:23 -0500 Message-Id: <883d5d681f426eb42ad65d805cfc138dea986b6c.1352925508.git.len.brown@intel.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1352925804-6746-1-git-send-email-lenb@kernel.org> References: <1352925804-6746-1-git-send-email-lenb@kernel.org> In-Reply-To: <39300ffb9b6666714c60735cf854e1280e4e75f4.1352925508.git.len.brown@intel.com> References: <39300ffb9b6666714c60735cf854e1280e4e75f4.1352925508.git.len.brown@intel.com> Reply-To: Len Brown Organization: Intel Open Source Technology Center Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Len Brown Turbostat assumed if it can't migrate to a CPU, then the CPU must have gone off-line and turbostat should re-initialize with the new topology. But if turbostat can not migrate because it is restricted by a cpuset, then it will fail to migrate even after re-initialization, resulting in an infinite loop. Spit out a warning when we can't migrate and endure only 2 re-initialize cycles in a row before giving up and exiting. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 3c063a0..77e76b1 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -656,8 +656,10 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) { int cpu = t->cpu_id; - if (cpu_migrate(cpu)) + if (cpu_migrate(cpu)) { + fprintf(stderr, "Could not migrate to CPU %d\n", cpu); return -1; + } t->tsc = rdtsc(); /* we are running on local CPU of interest */ @@ -1088,15 +1090,22 @@ int mark_cpu_present(int cpu) void turbostat_loop() { int retval; + int restarted = 0; restart: + restarted++; + retval = for_all_cpus(get_counters, EVEN_COUNTERS); if (retval < -1) { exit(retval); } else if (retval == -1) { + if (restarted > 1) { + exit(retval); + } re_initialize(); goto restart; } + restarted = 0; gettimeofday(&tv_even, (struct timezone *)NULL); while (1) {