Skip to content

Commit

Permalink
Merge tag 'pm-5.5-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/rafael/linux-pm

Pull additional power management updates from Rafael Wysocki:
 "These fix an ACPI EC driver bug exposed by the recent rework of the
  suspend-to-idle code flow, reintroduce frequency constraints into
  device PM QoS (in preparation for adding QoS support to devfreq), drop
  a redundant field from struct cpuidle_state and clean up Kconfig in
  some places.

  Specifics:

   - Avoid a race condition in the ACPI EC driver that may cause systems
     to be unable to leave suspend-to-idle (Rafael Wysocki)

   - Drop the "disabled" field, which is redundant, from struct
     cpuidle_state (Rafael Wysocki)

   - Reintroduce device PM QoS frequency constraints (temporarily
     introduced and than dropped during the 5.4 cycle) in preparation
     for adding QoS support to devfreq (Leonard Crestez)

   - Clean up indentation (in multiple places) and the cpuidle drivers
     help text in Kconfig (Krzysztof Kozlowski, Randy Dunlap)"

* tag 'pm-5.5-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
  ACPI: PM: s2idle: Rework ACPI events synchronization
  ACPI: EC: Rework flushing of pending work
  PM / devfreq: Add missing locking while setting suspend_freq
  PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY
  PM / QoS: Reorder pm_qos/freq_qos/dev_pm_qos structs
  PM / QoS: Initial kunit test
  PM / QoS: Redefine FREQ_QOS_MAX_DEFAULT_VALUE to S32_MAX
  power: avs: Fix Kconfig indentation
  cpufreq: Fix Kconfig indentation
  cpuidle: minor Kconfig help text fixes
  cpuidle: Drop disabled field from struct cpuidle_state
  cpuidle: Fix Kconfig indentation
  • Loading branch information
Linus Torvalds committed Dec 4, 2019
2 parents 63de374 + 1e4230f commit ef867c1
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 120 deletions.
8 changes: 4 additions & 4 deletions arch/sh/kernel/cpu/shmobile/cpuidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static struct cpuidle_driver cpuidle_driver = {
.enter = cpuidle_sleep_enter,
.name = "C2",
.desc = "SuperH Sleep Mode [SF]",
.disabled = true,
.flags = CPUIDLE_FLAG_UNUSABLE,
},
{
.exit_latency = 2300,
Expand All @@ -76,7 +76,7 @@ static struct cpuidle_driver cpuidle_driver = {
.enter = cpuidle_sleep_enter,
.name = "C3",
.desc = "SuperH Mobile Standby Mode [SF]",
.disabled = true,
.flags = CPUIDLE_FLAG_UNUSABLE,
},
},
.safe_state_index = 0,
Expand All @@ -86,10 +86,10 @@ static struct cpuidle_driver cpuidle_driver = {
int __init sh_mobile_setup_cpuidle(void)
{
if (sh_mobile_sleep_supported & SUSP_SH_SF)
cpuidle_driver.states[1].disabled = false;
cpuidle_driver.states[1].flags = CPUIDLE_FLAG_NONE;

if (sh_mobile_sleep_supported & SUSP_SH_STANDBY)
cpuidle_driver.states[2].disabled = false;
cpuidle_driver.states[2].flags = CPUIDLE_FLAG_NONE;

return cpuidle_register(&cpuidle_driver, NULL);
}
36 changes: 13 additions & 23 deletions drivers/acpi/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,26 +533,10 @@ static void acpi_ec_enable_event(struct acpi_ec *ec)
}

#ifdef CONFIG_PM_SLEEP
static bool acpi_ec_query_flushed(struct acpi_ec *ec)
static void __acpi_ec_flush_work(void)
{
bool flushed;
unsigned long flags;

spin_lock_irqsave(&ec->lock, flags);
flushed = !ec->nr_pending_queries;
spin_unlock_irqrestore(&ec->lock, flags);
return flushed;
}

static void __acpi_ec_flush_event(struct acpi_ec *ec)
{
/*
* When ec_freeze_events is true, we need to flush events in
* the proper position before entering the noirq stage.
*/
wait_event(ec->wait, acpi_ec_query_flushed(ec));
if (ec_query_wq)
flush_workqueue(ec_query_wq);
flush_scheduled_work(); /* flush ec->work */
flush_workqueue(ec_query_wq); /* flush queries */
}

static void acpi_ec_disable_event(struct acpi_ec *ec)
Expand All @@ -562,15 +546,21 @@ static void acpi_ec_disable_event(struct acpi_ec *ec)
spin_lock_irqsave(&ec->lock, flags);
__acpi_ec_disable_event(ec);
spin_unlock_irqrestore(&ec->lock, flags);
__acpi_ec_flush_event(ec);

/*
* When ec_freeze_events is true, we need to flush events in
* the proper position before entering the noirq stage.
*/
__acpi_ec_flush_work();
}

void acpi_ec_flush_work(void)
{
if (first_ec)
__acpi_ec_flush_event(first_ec);
/* Without ec_query_wq there is nothing to flush. */
if (!ec_query_wq)
return;

flush_scheduled_work();
__acpi_ec_flush_work();
}
#endif /* CONFIG_PM_SLEEP */

Expand Down
26 changes: 19 additions & 7 deletions drivers/acpi/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,16 @@ static int acpi_s2idle_prepare_late(void)
return 0;
}

static void acpi_s2idle_sync(void)
{
/*
* The EC driver uses the system workqueue and an additional special
* one, so those need to be flushed too.
*/
acpi_ec_flush_work();
acpi_os_wait_events_complete(); /* synchronize Notify handling */
}

static void acpi_s2idle_wake(void)
{
/*
Expand All @@ -1001,13 +1011,8 @@ static void acpi_s2idle_wake(void)
* should be missed by canceling the wakeup here.
*/
pm_system_cancel_wakeup();
/*
* The EC driver uses the system workqueue and an additional
* special one, so those need to be flushed too.
*/
acpi_os_wait_events_complete(); /* synchronize EC GPE processing */
acpi_ec_flush_work();
acpi_os_wait_events_complete(); /* synchronize Notify handling */

acpi_s2idle_sync();

rearm_wake_irq(acpi_sci_irq);
}
Expand All @@ -1024,6 +1029,13 @@ static void acpi_s2idle_restore_early(void)

static void acpi_s2idle_restore(void)
{
/*
* Drain pending events before restoring the working-state configuration
* of GPEs.
*/
acpi_os_wait_events_complete(); /* synchronize GPE processing */
acpi_s2idle_sync();

s2idle_wakeup = false;

acpi_enable_all_runtime_gpes();
Expand Down
4 changes: 4 additions & 0 deletions drivers/base/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ config DEBUG_TEST_DRIVER_REMOVE
unusable. You should say N here unless you are explicitly looking to
test this functionality.

config PM_QOS_KUNIT_TEST
bool "KUnit Test for PM QoS features"
depends on KUNIT

config HMEM_REPORTING
bool
default n
Expand Down
1 change: 1 addition & 0 deletions drivers/base/power/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o
obj-$(CONFIG_PM_TRACE_RTC) += trace.o
obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o
obj-$(CONFIG_HAVE_CLK) += clock_ops.o
obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o

ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
117 changes: 117 additions & 0 deletions drivers/base/power/qos-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2019 NXP
*/
#include <kunit/test.h>
#include <linux/pm_qos.h>

/* Basic test for aggregating two "min" requests */
static void freq_qos_test_min(struct kunit *test)
{
struct freq_constraints qos;
struct freq_qos_request req1, req2;
int ret;

freq_constraints_init(&qos);
memset(&req1, 0, sizeof(req1));
memset(&req2, 0, sizeof(req2));

ret = freq_qos_add_request(&qos, &req1, FREQ_QOS_MIN, 1000);
KUNIT_EXPECT_EQ(test, ret, 1);
ret = freq_qos_add_request(&qos, &req2, FREQ_QOS_MIN, 2000);
KUNIT_EXPECT_EQ(test, ret, 1);

KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 2000);

ret = freq_qos_remove_request(&req2);
KUNIT_EXPECT_EQ(test, ret, 1);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 1000);

ret = freq_qos_remove_request(&req1);
KUNIT_EXPECT_EQ(test, ret, 1);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN),
FREQ_QOS_MIN_DEFAULT_VALUE);
}

/* Test that requests for MAX_DEFAULT_VALUE have no effect */
static void freq_qos_test_maxdef(struct kunit *test)
{
struct freq_constraints qos;
struct freq_qos_request req1, req2;
int ret;

freq_constraints_init(&qos);
memset(&req1, 0, sizeof(req1));
memset(&req2, 0, sizeof(req2));
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX),
FREQ_QOS_MAX_DEFAULT_VALUE);

ret = freq_qos_add_request(&qos, &req1, FREQ_QOS_MAX,
FREQ_QOS_MAX_DEFAULT_VALUE);
KUNIT_EXPECT_EQ(test, ret, 0);
ret = freq_qos_add_request(&qos, &req2, FREQ_QOS_MAX,
FREQ_QOS_MAX_DEFAULT_VALUE);
KUNIT_EXPECT_EQ(test, ret, 0);

/* Add max 1000 */
ret = freq_qos_update_request(&req1, 1000);
KUNIT_EXPECT_EQ(test, ret, 1);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX), 1000);

/* Add max 2000, no impact */
ret = freq_qos_update_request(&req2, 2000);
KUNIT_EXPECT_EQ(test, ret, 0);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX), 1000);

/* Remove max 1000, new max 2000 */
ret = freq_qos_remove_request(&req1);
KUNIT_EXPECT_EQ(test, ret, 1);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX), 2000);
}

/*
* Test that a freq_qos_request can be added again after removal
*
* This issue was solved by commit 05ff1ba412fd ("PM: QoS: Invalidate frequency
* QoS requests after removal")
*/
static void freq_qos_test_readd(struct kunit *test)
{
struct freq_constraints qos;
struct freq_qos_request req;
int ret;

freq_constraints_init(&qos);
memset(&req, 0, sizeof(req));
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN),
FREQ_QOS_MIN_DEFAULT_VALUE);

/* Add */
ret = freq_qos_add_request(&qos, &req, FREQ_QOS_MIN, 1000);
KUNIT_EXPECT_EQ(test, ret, 1);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 1000);

/* Remove */
ret = freq_qos_remove_request(&req);
KUNIT_EXPECT_EQ(test, ret, 1);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN),
FREQ_QOS_MIN_DEFAULT_VALUE);

/* Add again */
ret = freq_qos_add_request(&qos, &req, FREQ_QOS_MIN, 2000);
KUNIT_EXPECT_EQ(test, ret, 1);
KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 2000);
}

static struct kunit_case pm_qos_test_cases[] = {
KUNIT_CASE(freq_qos_test_min),
KUNIT_CASE(freq_qos_test_maxdef),
KUNIT_CASE(freq_qos_test_readd),
{},
};

static struct kunit_suite pm_qos_test_module = {
.name = "qos-kunit-test",
.test_cases = pm_qos_test_cases,
};
kunit_test_suite(pm_qos_test_module);
Loading

0 comments on commit ef867c1

Please sign in to comment.