Skip to contentSkip to conversation

new C-state policy

RFC In review Shaohua Li 3 participants 8 messages Jan 10, 2006 – Jan 12, 2006 6 messages not in the archive ACPI

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

RFC 2/2 new C-state policy

This is a new C-state policy, based on Thomas's one.
http://lkml.org/lkml/2005/4/19/96

Enhancements:
1. it does all policy calculation before going into idle, so other tasks can be quickly scheduled after idle.
2. it works w/wo dyntick feature.
3. more tunning parameters and hopefully better policy
4. using pm timer for time accounting, so jiffy doesn't impact the policy.

Now we use below rules:
1. if cpu activity is high, use C1.
2. if average sleeping time is above or below threshold, do promotion/demotion.
3. bm activity calculation is similar with current one, but slightly changed to work with dyntick feature.

It's still not very good. Comments/suggestions are highly appreciated.

Thanks,
Shaohua
---

 linux-2.6.15-rc7-root/drivers/acpi/Kconfig                |    7 
 linux-2.6.15-rc7-root/drivers/acpi/Makefile               |    1 
 linux-2.6.15-rc7-root/drivers/acpi/processor_cstate_new.c |  373 ++++++++++++++
 3 files changed, 381 insertions(+)
drivers/acpi/Kconfig renamed from drivers/acpi/Kconfig~new-policy +7 -0
diff -puN drivers/acpi/Kconfig~new-policy drivers/acpi/Kconfig
@@ -143,6 +143,13 @@ config ACPI_PROCESSOR
 	  support it.  It is required by several flavors of cpufreq
 	  Performance-state drivers.
 
+config ACPI_NEW_CSTATE_POLICY
+	tristate "New C-state policy"
+	depends on ACPI_PROCESSOR && EXPERIMENTAL
+	default m
+	help
+	 New policy for ACPI C-state. It's friendly with dyn-HZ.
+
 config ACPI_HOTPLUG_CPU
 	bool
 	depends on ACPI_PROCESSOR && HOTPLUG_CPU
drivers/acpi/Makefile renamed from drivers/acpi/Makefile~new-policy +1 -0
diff -puN drivers/acpi/Makefile~new-policy drivers/acpi/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_ACPI_HOTKEY)	+= hotkey.o
 obj-y				+= pci_root.o pci_link.o pci_irq.o pci_bind.o
 obj-$(CONFIG_ACPI_POWER)	+= power.o
 obj-$(CONFIG_ACPI_PROCESSOR)	+= processor.o
+obj-$(CONFIG_ACPI_NEW_CSTATE_POLICY) += processor_cstate_new.o
 obj-$(CONFIG_ACPI_CONTAINER)	+= container.o
 obj-$(CONFIG_ACPI_THERMAL)	+= thermal.o
 obj-$(CONFIG_ACPI_SYSTEM)	+= system.o event.o
drivers/acpi/processor_cstate_new.c new file +373 -0

373 lines not on this page · raw message

_

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1136866376.5750.29.camel-U5EdaLXB8smDugQYiPIPGdh3ngVCH38I@public.gmane.org

#2 lore raw

Hi,

Quoted 3 lines · Shaohua Li

Enhancements:
1. it does all policy calculation before going into idle, so other tasks can be quickly scheduled after idle.

This is much more tricky:

if CONFIG_PREEMPTION isn't set, this is (mostly) correct.

IDLE:

	acpi_processor_idle()
	{
		local_irq_disable()
		... -> pre_cx()
		? need_resched()
		ENTER_CSTATE
		local_irq_enable()
		... -> post_cx()
	}

However: all calculations are done with IRQs -- needlessly -- off. All IRQs appearing between local_irq_disable() and ENTER_CSTATE will cause a failed transition, and only be handled afterwards. And that's bad for two reasons:
firstly it took some time until we handled the IRQ, secondly because failed transitions into C-States cost time and power and thus energy. Therefore, the span between the putting IRQs off and entering the C-State must be quite small.

Also, if CONFIG_PREEMTPION is set, something else happens: the idle task's instruction pointer points right after the "local_irq_enable()" call. As once we enabled IRQs, we also allowed the lowest-priority idle thread to be preempted by any other process wanting to run. Therefore, once the system becomes idle, we'll first do the "->post_cx()" calculation (with IRQs off!) before going back to the loop which calls acpi_processor_idle() again, and only then IRQs are disabled, "->pre_cx()" is called, and so on.

As the behaviour is so totally different whether CONFIG_PREEMPTION is set or not, I'd suggest the following (untested): add a "schedule()" right after "local_irq_enable()". This will force the same behaviour as CONFIG_PREEMPTION does currently also for the !CONFIG_PREEMTPION case.

Quoted 1 line

It's still not very good. Comments/suggestions are highly appreciated.

Take a look at my four patches, please, and all the tricks and tweaks they do ;-)

drivers/acpi/processor_cstate_new.c line 139

Quoted 2 lines
drivers/acpi/processor_cstate_new.c new file +2 -0
+	while (diff) {
+		/* if we didn't get called, assume there was busmaster activity */

... this turned out to be a bad idea, especially with dyn ticks enabled.

drivers/acpi/processor_cstate_new.c line 147

Quoted 8 lines
drivers/acpi/processor_cstate_new.c new file +8 -0
+		diff --;
+		if (diff)
+			pr->power.bm_activity |= 0x1;
+		pr->power.bm_activity <<= 1;
+	}
+
+	if (bm_status) {
+		pr->power.bm_activity++;

|= 0x1 not ++;

Also, the actual checking for bm_activity should be common code, e.g.

int acpi_processor_is_there_bm_activity()

{
	if (...)
		return 1;
	return 0;
}

Thanks,
Dominik
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#4 lore raw
Quoted 38 lines · Dominik Brodowski

Hi,

Quoted 3 lines · Shaohua Li

Enhancements:
1. it does all policy calculation before going into idle, so other tasks can be quickly scheduled after idle.

This is much more tricky:

if CONFIG_PREEMPTION isn't set, this is (mostly) correct.

IDLE:

	acpi_processor_idle()
	{
		local_irq_disable()
		... -> pre_cx()
		? need_resched()
		ENTER_CSTATE
		local_irq_enable()
		... -> post_cx()
	}

However: all calculations are done with IRQs -- needlessly -- off. All IRQs appearing between local_irq_disable() and ENTER_CSTATE will cause a failed transition, and only be handled afterwards. And that's bad for two reasons:
firstly it took some time until we handled the IRQ, secondly because failed transitions into C-States cost time and power and thus energy. Therefore, the span between the putting IRQs off and entering the C-State must be quite small.

Also, if CONFIG_PREEMTPION is set, something else happens: the idle task's instruction pointer points right after the "local_irq_enable()" call. As once we enabled IRQs, we also allowed the lowest-priority idle thread to be preempted by any other process wanting to run. Therefore, once the system becomes idle, we'll first do the "->post_cx()" calculation (with IRQs off!) before going back to the loop which calls acpi_processor_idle() again, and only then IRQs are disabled, "->pre_cx()" is called, and so on.

Quoted 4 lines

As the behaviour is so totally different whether CONFIG_PREEMPTION is set or not, I'd suggest the following (untested): add a "schedule()" right after "local_irq_enable()". This will force the same behaviour as CONFIG_PREEMPTION does currently also for the !CONFIG_PREEMTPION case.

I only do bm check with irq disabled. promotion/demotion calculation is done with irq enabled. As I said, idle currently can't be preempted at any places.

Quoted 3 lines
Quoted 1 line

It's still not very good. Comments/suggestions are highly appreciated.

Take a look at my four patches, please, and all the tricks and tweaks they do ;-)

Sure, I did look at your patches. They did have many good staffs. As I said, Len hopes smooth move, so adding a new module might be better.

Quoted 3 lines

drivers/acpi/processor_cstate_new.c line 139

Quoted 2 lines
drivers/acpi/processor_cstate_new.c new file +2 -0
+	while (diff) {
+		/* if we didn't get called, assume there was busmaster activity */

... this turned out to be a bad idea, especially with dyn ticks enabled.

I only did this when there is bus activity. With this trick, dyn ticks works fine in my test.

Quoted 9 lines

drivers/acpi/processor_cstate_new.c line 147

Quoted 8 lines
drivers/acpi/processor_cstate_new.c new file +8 -0
+		diff --;
+		if (diff)
+			pr->power.bm_activity |= 0x1;
+		pr->power.bm_activity <<= 1;
+	}
+
+	if (bm_status) {
+		pr->power.bm_activity++;

|= 0x1 not ++;

Ok.

Quoted 2 lines

Also, the actual checking for bm_activity should be common code, e.g.

It's policy specific. Each policy could have its own method to calculate bm_activity.

Thanks,
Shaohua

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1136944855.5750.61.camel-U5EdaLXB8smDugQYiPIPGdh3ngVCH38I@public.gmane.org

#6 lore raw

Hi,

Quoted 7 lines · Shaohua Li
Quoted 4 lines

As the behaviour is so totally different whether CONFIG_PREEMPTION is set or not, I'd suggest the following (untested): add a "schedule()" right after "local_irq_enable()". This will force the same behaviour as CONFIG_PREEMPTION does currently also for the !CONFIG_PREEMTPION case.

I only do bm check with irq disabled. promotion/demotion calculation is done with irq enabled. As I said, idle currently can't be preempted at any places.

*panic* -- you're disabling IRQs, checking for bm activity (1), then re-enabling IRQs (2), then doing some calculations (3), then disabling IRQs (4)again? This calls for "false negatives", i.e. bus mastering activity being initiated between
(2) and (4), causing faulty transitions afterwards....

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It's still not very good. Comments/suggestions are highly appreciated.

Take a look at my four patches, please, and all the tricks and tweaks they do ;-)

Sure, I did look at your patches. They did have many good staffs. As I said, Len hopes smooth move, so adding a new module might be better.

Sure, for the policy changes yes. However, for the staticistics patch (which was 3/4) the core is the place to go, IMHO...

Quoted 3 lines
Quoted 1 line

Also, the actual checking for bm_activity should be common code, e.g.

It's policy specific. Each policy could have its own method to calculate bm_activity.

What to do once bm_activity is or was detected, yes. How to determine whether there is current bus mastering activity, no -- that's core stuff, not policy stuff.

Thanks,
Dominik
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 10 lines · Dominik Brodowski

Hi,

Quoted 3 lines
Quoted 1 line

Also, the actual checking for bm_activity should be common code, e.g.

It's policy specific. Each policy could have its own method to calculate bm_activity.

What to do once bm_activity is or was detected, yes. How to determine whether there is current bus mastering activity, no -- that's core stuff, not policy stuff.

I had the experience that tweaking how bm_activity is detected could help a lot. An aggressive policy might also accept some faulty transitions in respect of more power saving achievements.
What about the way in the middle?:
A general check_bm_activity() function. This one can be overridden by more complex policy drivers/modules.

I hope to get some time the next days to play with all this...

Thomas
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Hi,

Quoted 6 lines · Thomas Renninger
Quoted 4 lines

What to do once bm_activity is or was detected, yes. How to determine whether there is current bus mastering activity, no -- that's core stuff, not policy stuff.

I had the experience that tweaking how bm_activity is detected could help a lot.

I think we still don't speak about the same topic:

a) how to detect bus mastering activity?

	acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status, ACPI_MTX_DO_NOT_LOCK);
	if (errata.piix4.bmisx) {
        	if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
                   || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
				pr->power.bm_activity++;
	}
	=> generic

b) what to do?
demote/allow faulty transition/...
=> driver-specific

So all I want is the following:

static int acpi_processor_bm_status(void) {
	u32 bm_status;

	acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status, ACPI_MTX_DO_NOT_LOCK);
	if (bm_status)
		return 1;
	else if (errata.piix4.bmisx) {
        	if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
                   || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
			return 1;
	}

	return 0;
}

in order to not having to copy this code into each policy. What to do with the return value of acpi_processor_bm_status() is then up to the policy.

Dominik

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw
Quoted 10 lines · Dominik Brodowski

Hi,

Quoted 5 lines · Thomas Renninger
Quoted 4 lines

What to do once bm_activity is or was detected, yes. How to determine whether there is current bus mastering activity, no -- that's core stuff, not policy stuff.

I had the experience that tweaking how bm_activity is detected could help a lot.

I think we still don't speak about the same topic:

Ok, that's the problem.

Quoted 18 lines

a) how to detect bus mastering activity?

	acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status, ACPI_MTX_DO_NOT_LOCK);
	if (errata.piix4.bmisx) {
        	if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
                   || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
				pr->power.bm_activity++;
	}
	=> generic

b) what to do?
demote/allow faulty transition/...
=> driver-specific

So all I want is the following:

Quoted 15 lines
static int acpi_processor_bm_status(void) {
	u32 bm_status;

	acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status, ACPI_MTX_DO_NOT_LOCK);
	if (bm_status)
		return 1;
	else if (errata.piix4.bmisx) {
        	if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
                   || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
			return 1;
	}

	return 0;
}

Yep, now I get your point and agree.

Thomas
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#13 lore raw
In reply to a message not in the archive
Quoted 5 lines · Dominik Brodowski
Quoted 4 lines · Shaohua Li
Quoted 4 lines

As the behaviour is so totally different whether CONFIG_PREEMPTION is set or not, I'd suggest the following (untested): add a "schedule()" right after "local_irq_enable()". This will force the same behaviour as CONFIG_PREEMPTION does currently also for the !CONFIG_PREEMTPION case.

Quoted 8 lines
Quoted 3 lines

I only do bm check with irq disabled. promotion/demotion calculation is done with irq enabled. As I said, idle currently can't be preempted at any places.

*panic* -- you're disabling IRQs, checking for bm activity (1), then re-enabling IRQs (2), then doing some calculations (3), then disabling IRQs (4)again? This calls for "false negatives", i.e. bus mastering activity being initiated between
(2) and (4), causing faulty transitions afterwards....

It is unavoidable regardless any policy. Disabling IRQs or doing calculations later doesn't change it, unless you do bm calculation twice, one is just before going to C-state the other is just after C-state. But might not be worthy doing to me ....

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It's still not very good. Comments/suggestions are highly appreciated.

Take a look at my four patches, please, and all the tricks and tweaks they do ;-)

Sure, I did look at your patches. They did have many good staffs. As I said, Len hopes smooth move, so adding a new module might be better.

Sure, for the policy changes yes. However, for the staticistics patch (which was 3/4) the core is the place to go, IMHO...

Sure. I actually have a similar patch doing this. You are quicker :). Venkatesh suggested export the statistics by sysfs instead of mess proc, how about it?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Also, the actual checking for bm_activity should be common code, e.g.

It's policy specific. Each policy could have its own method to calculate bm_activity.

What to do once bm_activity is or was detected, yes. How to determine whether there is current bus mastering activity, no -- that's core stuff, not policy stuff.

Thanks, I understand your point now. I'll update the first patch.

Thanks,
Shaohua

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html