All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Joachim Deguara" <joachim.deguara@amd.com>
To: "Langsdorf, Mark" <mark.langsdorf@amd.com>
Cc: ak@suse.de, discuss@x86-64.org, linux-kernel@vger.kernel.org,
	cpufreq@lists.linux.org.uk
Subject: RE: [discuss] Re: [PATCH] Allow all Opteron processors to change pstate at same time
Date: Mon, 10 Jul 2006 14:45:55 +0200	[thread overview]
Message-ID: <1152535555.4897.16.camel@lapdog.site> (raw)
In-Reply-To: <84EA05E2CA77634C82730353CBE3A84303218E99@SAUSEXMB1.amd.com>

[-- Attachment #1: Type: text/plain, Size: 544 bytes --]

On Fri, 2006-07-07 at 12:36 -0500, Langsdorf, Mark wrote: 
> > Your patch seems to be ^M damaged.
> 
> I'll smack my mailer around again.  Sorry about that.

revised patch attached (also corrected tscsync qualifier and initial
state of req_state).

> > I'm still dubious if the result is really correct if the 
> > hardware wasn't designed to guarantee synchronous TSC operation.
> > 
> > Can you do the following test please? 
> 
> We'll try to have the results back by Monday evening.

may have to wait till Tuesday for my results.

-joachim

[-- Attachment #2: 2.6.18-rc1-pntscsync.patch --]
[-- Type: text/x-patch, Size: 6927 bytes --]

--- arch/i386/kernel/cpu/cpufreq/powernow-k8.c.orig	2006-07-10 13:25:47.000000000 +0200
+++ arch/i386/kernel/cpu/cpufreq/powernow-k8.c	2006-07-10 14:15:37.000000000 +0200
@@ -46,13 +46,15 @@
 
 #define PFX "powernow-k8: "
 #define BFX PFX "BIOS error: "
-#define VERSION "version 2.00.00"
+#define VERSION "version 2.10.00"
 #include "powernow-k8.h"
 
 /* serialize freq changes  */
 static DEFINE_MUTEX(fidvid_mutex);
 
 static struct powernow_k8_data *powernow_data[NR_CPUS];
+static int *req_state = NULL;
+static int tscsync = 0;
 
 static int cpu_family = CPU_OPTERON;
 
@@ -205,6 +207,17 @@ static int write_new_fid(struct powernow
 	dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n",
 		fid, lo, data->plllock * PLL_LOCK_CONVERSION);
 
+	if (tscsync) {
+		int i;
+		cpumask_t oldmask = current->cpus_allowed;
+		for_each_online_cpu(i) {
+			set_cpus_allowed(current, cpumask_of_cpu(i));
+			schedule();
+			wrmsr(MSR_FIDVID_CTL, lo & ~MSR_C_LO_INIT_FID_VID, data->plllock * PLL_LOCK_CONVERSION);
+		}
+		set_cpus_allowed(current, oldmask);
+		schedule();
+	}
 	do {
 		wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
 		if (i++ > 100) {
@@ -247,6 +260,17 @@ static int write_new_vid(struct powernow
 	dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n",
 		vid, lo, STOP_GRANT_5NS);
 
+	if (tscsync) {
+		int i;
+		cpumask_t oldmask = current->cpus_allowed;
+		for_each_online_cpu(i) {
+			set_cpus_allowed(current, cpumask_of_cpu(i));
+			schedule();
+			wrmsr(MSR_FIDVID_CTL, lo & ~MSR_C_LO_INIT_FID_VID, STOP_GRANT_5NS);
+		}
+		set_cpus_allowed(current, oldmask);
+		schedule();
+	}
 	do {
 		wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
 		if (i++ > 100) {
@@ -386,7 +410,8 @@ static int core_frequency_transition(str
 	}
 
 	if (data->currfid == reqfid) {
-		printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", data->currfid);
+		if (!tscsync)
+			printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", data->currfid);
 		return 0;
 	}
 
@@ -960,9 +985,21 @@ static int transition_frequency_fidvid(s
 	u32 vid = 0;
 	int res, i;
 	struct cpufreq_freqs freqs;
+	cpumask_t changing_cores;
 
 	dprintk("cpu %d transition to index %u\n", smp_processor_id(), index);
 
+	/* if all processors are transitioning in step, find the highest
+	 * current state and go to that
+         */
+
+	if (tscsync && req_state) {
+		req_state[smp_processor_id()] = index;
+		for_each_online_cpu(i) 
+			if (req_state[i] < index)
+				index = req_state[i];
+	}
+
 	/* fid/vid correctness check for k8 */
 	/* fid are the lower 8 bits of the index we stored into
 	 * the cpufreq frequency table in find_psb_table, vid
@@ -983,6 +1020,8 @@ static int transition_frequency_fidvid(s
 	}
 
 	if ((fid < HI_FID_TABLE_BOTTOM) && (data->currfid < HI_FID_TABLE_BOTTOM)) {
+		if (tscsync && (data->currfid == fid))
+			return 0;
 		printk(KERN_ERR PFX
 		       "ignoring illegal change in lo freq table-%x to 0x%x\n",
 		       data->currfid, fid);
@@ -994,7 +1033,11 @@ static int transition_frequency_fidvid(s
 	freqs.old = find_khz_freq_from_fid(data->currfid);
 	freqs.new = find_khz_freq_from_fid(fid);
 
-	for_each_cpu_mask(i, *(data->available_cores)) {
+	if (tscsync)
+		changing_cores = cpu_online_map;
+	else
+		changing_cores = *(data->available_cores);
+	for_each_cpu_mask(i, changing_cores) {
 		freqs.cpu = i;
 		cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
 	}
@@ -1002,10 +1045,16 @@ static int transition_frequency_fidvid(s
 	res = transition_fid_vid(data, fid, vid);
 	freqs.new = find_khz_freq_from_fid(data->currfid);
 
-	for_each_cpu_mask(i, *(data->available_cores)) {
+	for_each_cpu_mask(i, changing_cores) {
 		freqs.cpu = i;
 		cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
 	}
+	if (tscsync) 
+		for_each_online_cpu(i)
+			if (powernow_data[i]) {
+				powernow_data[i]->currfid = data->currfid;
+				powernow_data[i]->currvid = data->currvid;
+			}
 	return res;
 }
 
@@ -1054,7 +1103,7 @@ static int powernowk8_target(struct cpuf
 	u32 checkfid;
 	u32 checkvid;
 	unsigned int newstate;
-	int ret = -EIO;
+	int ret = 0;//-EIO;
 
 	if (!data)
 		return -EINVAL;
@@ -1089,7 +1138,7 @@ static int powernowk8_target(struct cpuf
 		dprintk("targ: curr fid 0x%x, vid 0x%x\n",
 		data->currfid, data->currvid);
 
-		if ((checkvid != data->currvid) || (checkfid != data->currfid)) {
+		if (!tscsync && ((checkvid != data->currvid) || (checkfid != data->currfid))) {
 			printk(KERN_INFO PFX
 				"error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n",
 				checkfid, data->currfid, checkvid, data->currvid);
@@ -1100,7 +1149,6 @@ static int powernowk8_target(struct cpuf
 		goto err_out;
 
 	mutex_lock(&fidvid_mutex);
-
 	powernow_k8_acpi_pst_values(data, newstate);
 
 	if (cpu_family == CPU_HW_PSTATE)
@@ -1137,6 +1185,32 @@ static int powernowk8_verify(struct cpuf
 	return cpufreq_frequency_table_verify(pol, data->powernow_table);
 }
 
+/* On an MP system that is transitioning all cores in sync, adjust the
+ * vids for each frequency to the highest.  Otherwise, systems made up
+ * of different steppings may fail.
+ */
+static void sync_tables(int curcpu)
+{
+	int j;
+	for (j = 0; j < powernow_data[curcpu]->numps; j++) {
+		int i;
+		int maxvid = 0;
+		for_each_online_cpu(i) {
+			int testvid;
+			if (!powernow_data[i] || !powernow_data[i]->powernow_table)
+				continue;
+			testvid = powernow_data[i]->powernow_table[j].index & 0xff00;
+			if (testvid > maxvid)
+				maxvid = testvid;
+		}	
+		for_each_online_cpu(i) {
+			if (!powernow_data[i] || ! powernow_data[i]->powernow_table)
+				continue;
+			powernow_data[i]->powernow_table[j].index &= 0xff;
+			powernow_data[i]->powernow_table[j].index |= maxvid;
+		}
+	}
+}
 /* per CPU init entry point to the driver */
 static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
 {
@@ -1241,6 +1315,8 @@ static int __cpuinit powernowk8_cpu_init
 
 	powernow_data[pol->cpu] = data;
 
+	if (tscsync && (cpu_family == CPU_OPTERON))
+		sync_tables(pol->cpu);
 	return 0;
 
 err_out:
@@ -1323,6 +1399,16 @@ static int __cpuinit powernowk8_init(voi
 	}
 
 	if (supported_cpus == num_online_cpus()) {
+		if (tscsync) {
+			req_state = kalloc(sizeof(int)*NR_CPUS, GFP_KERNEL);
+			if (!req_state) {
+				printk(KERN_ERR PFX "Unable to allocate memory!\n");
+				return -ENOMEM;
+			}
+			//necessary for dual-cores (99=just a large number)
+			for(i=0; i < NR_CPUS; i++)
+			    req_state[i] = 99;
+		}
 		printk(KERN_INFO PFX "Found %d %s "
 			"processors (" VERSION ")\n", supported_cpus,
 			boot_cpu_data.x86_model_id);
@@ -1337,6 +1423,9 @@ static void __exit powernowk8_exit(void)
 {
 	dprintk("exit\n");
 
+	if (tscsync)
+		kfree(req_state);
+
 	cpufreq_unregister_driver(&cpufreq_amd64_driver);
 }
 
@@ -1346,3 +1435,6 @@ MODULE_LICENSE("GPL");
 
 late_initcall(powernowk8_init);
 module_exit(powernowk8_exit);
+
+module_param(tscsync, int, 0);
+MODULE_PARM_DESC(tscsync, "enable tsc by synchronizing powernow-k8 changes");

  reply	other threads:[~2006-07-10 12:45 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-06 20:31 [PATCH] Allow all Opteron processors to change pstate at same time Mark Langsdorf
2006-07-07 12:10 ` Andi Kleen
2006-07-07 17:36   ` [discuss] " Langsdorf, Mark
2006-07-10 12:45     ` Joachim Deguara [this message]
2006-07-10 13:02       ` Joachim Deguara
2006-07-07 18:14   ` Scott Lampert
2006-07-07 18:26     ` Langsdorf, Mark
2006-07-11 12:55   ` Joachim Deguara
2006-07-11 13:07     ` Andi Kleen
2006-07-11 13:14       ` Arjan van de Ven
2006-07-11 16:15         ` Alan Cox
2006-07-11 16:01           ` Arjan van de Ven
2006-07-11 16:01             ` Arjan van de Ven
2006-07-11 16:04           ` Andi Kleen
2006-07-11 13:31       ` Langsdorf, Mark
2006-07-11 13:34         ` Arjan van de Ven
2006-07-11 13:51           ` Andi Kleen
2006-07-11 13:14     ` [OT] Evolution use (was: Re: [discuss] Re: [PATCH] Allow all Opteron processors to change pstate at same time) Xavier Bestel
2006-07-12 14:06     ` [discuss] Re: [PATCH] Allow all Opteron processors to change pstate at same time Joachim Deguara
2006-07-12 14:54       ` Andi Kleen
2006-07-25 21:47   ` Langsdorf, Mark
2006-07-26 11:31     ` Joachim Deguara
2006-07-26 16:42   ` Langsdorf, Mark
2006-07-26 16:54     ` Andi Kleen
2006-07-26 16:54       ` Andi Kleen
2006-07-26 18:34       ` Langsdorf, Mark
2006-07-26 18:53         ` Andi Kleen
2006-07-26 18:53           ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2006-07-12 16:11 shin, jacob
2006-07-12 16:14 ` Langsdorf, Mark
2006-07-13 13:06 ` Pavel Machek
2006-07-13 14:32   ` Joachim Deguara
2006-07-16  1:56     ` Pavel Machek
2006-07-17  7:37       ` Joachim Deguara
2006-07-20 15:59         ` Pavel Machek
2006-07-13 13:37 Bhavana Nagendra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1152535555.4897.16.camel@lapdog.site \
    --to=joachim.deguara@amd.com \
    --cc=ak@suse.de \
    --cc=cpufreq@lists.linux.org.uk \
    --cc=discuss@x86-64.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.langsdorf@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.