Skip to content

Commit 7360933

Browse files
committed
[CR][aarch64] Optimize CPPC: cleanup HWP (rev. 6)
* Replace `smp_call_function_single()` with `smp_call_on_cpu()` to allow holding `pcc_lock` whilst `cpc_read` * Update CPPC ratios right after recomputing the factory frequency
1 parent de63bb1 commit 7360933

5 files changed

Lines changed: 63 additions & 122 deletions

File tree

aarch64/arm_reg.h

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -916,51 +916,3 @@ typedef union
916916
RSVD : 64-16;
917917
};
918918
} AMCNTENSET;
919-
920-
typedef struct
921-
{
922-
unsigned int
923-
Highest, /* highest_perf */
924-
Guaranteed, /* guaranteed_perf|nominal_perf */
925-
Most_Efficient, /* nominal_freq */
926-
Lowest; /* lowest_freq */
927-
} HWP_CAPABILITIES;
928-
929-
typedef union
930-
{
931-
unsigned long long value;
932-
struct
933-
{
934-
unsigned long long
935-
EN_Guarantee_Chg: 1-0,
936-
EN_Excursion_Min: 2-1,
937-
EN_Highest_Chg : 3-2,
938-
EN_PECI_OVERRIDE: 4-3,
939-
ReservedBits : 64-4; /* **Must be zero** */
940-
};
941-
} HWP_INTERRUPT;
942-
943-
typedef struct
944-
{
945-
struct
946-
{
947-
unsigned int
948-
Minimum_Perf,
949-
Maximum_Perf,
950-
Desired_Perf, /* reference_perf */
951-
Energy_Pref;
952-
};
953-
struct
954-
{
955-
unsigned long long
956-
ReservedBits1 : 32-0,
957-
Activity_Window : 42-32,
958-
Package_Control : 43-42,
959-
ReservedBits2 : 59-43,
960-
Act_Window_Valid: 60-59, /* Activity_Window Valid; Default=0 */
961-
EPP_Valid : 61-60, /*1:[HWP_REQUEST];0:[HWP_REQUEST_PKG]*/
962-
Desired_Valid : 62-61, /* -> Desired_Perf */
963-
Maximum_Valid : 63-62, /* -> Maximum_Perf */
964-
Minimum_Valid : 64-63; /* -> Minimum_Perf */
965-
};
966-
} HWP_REQUEST;

aarch64/corefreq-api.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ typedef struct
4646
struct {
4747
enum THERM_PWR_EVENTS Events[eDIM];
4848
};
49-
HWP_CAPABILITIES HWP_Capabilities;
50-
HWP_INTERRUPT HWP_Interrupt;
51-
HWP_REQUEST HWP_Request;
5249
struct ACPI_CPPC_STRUCT {
5350
unsigned int Highest,
5451
Guaranteed,

aarch64/corefreqd.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -909,43 +909,43 @@ void PowerThermal( RO(SHM_STRUCT) *RO(Shm), RO(PROC) *RO(Proc),
909909

910910
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Capabilities.Highest.N = \
911911
CLOCK_KHz(float,
912-
( RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Most_Efficient
913-
* RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Highest )
914-
/ RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Guaranteed );
912+
( RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Efficient
913+
* RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Highest )
914+
/ RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Guaranteed );
915915

916916
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Capabilities.Guaranteed.N = \
917917
CLOCK_KHz(float,
918-
RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Most_Efficient
918+
RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Efficient
919919
);
920920

921921
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Capabilities.Most_Efficient.N = \
922922
CLOCK_KHz(float,
923-
RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Most_Efficient
923+
RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Efficient
924924
);
925925

926926
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Capabilities.Lowest.N = \
927927
CLOCK_KHz(float,
928-
RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Lowest
928+
RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Lowest
929929
);
930930

931931
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Request.Minimum_Perf.N = \
932932
(float)
933-
( RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Most_Efficient
934-
* RO(Core, AT(cpu))->PowerThermal.HWP_Request.Minimum_Perf )
935-
/ (100000.0 * RO(Core, AT(cpu))->PowerThermal.HWP_Request.Desired_Perf);
933+
( RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Efficient
934+
* RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Minimum )
935+
/ (100000.0 * RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Desired);
936936

937937
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Request.Maximum_Perf.N = \
938938
CLOCK_KHz(float,
939-
( RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Most_Efficient
940-
* RO(Core, AT(cpu))->PowerThermal.HWP_Request.Maximum_Perf )
941-
/ RO(Core, AT(cpu))->PowerThermal.HWP_Capabilities.Guaranteed );
939+
( RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Efficient
940+
* RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Maximum )
941+
/ RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Guaranteed );
942942

943943
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Request.Desired_Perf.N = \
944944
(float)
945-
( RO(Core, AT(cpu))->PowerThermal.HWP_Request.Desired_Perf ) / 10.0;
945+
( RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Desired ) / 10.0;
946946

947947
RO(Shm)->Cpu[cpu].PowerThermal.HWP.Request.Energy_Pref = \
948-
RO(Core, AT(cpu))->PowerThermal.HWP_Request.Energy_Pref;
948+
RO(Core, AT(cpu))->PowerThermal.ACPI_CPPC.Energy;
949949

950950
memcpy( &RO(Shm)->Cpu[cpu].ThermalPoint,
951951
&RO(Core, AT(cpu))->ThermalPoint,

aarch64/corefreqk.c

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,35 +3505,7 @@ static void PerCore_Compute_ACPI_CPPC(CORE_RO *Core)
35053505
{
35063506
unsigned long long scaledFreq;
35073507

3508-
if (PUBLIC(RO(Proc))->Features.OSPM_EPP) {
3509-
Get_EPP_ACPI_CPPC(Core->Bind);
3510-
}
3511-
3512-
Compute_ACPI_CPPC_Bounds(Core->Bind);
3513-
3514-
Core->PowerThermal.HWP_Capabilities.Highest = \
3515-
Core->PowerThermal.ACPI_CPPC.Highest;
3516-
3517-
Core->PowerThermal.HWP_Capabilities.Guaranteed = \
3518-
Core->PowerThermal.ACPI_CPPC.Guaranteed;
3519-
3520-
Core->PowerThermal.HWP_Capabilities.Most_Efficient = \
3521-
Core->PowerThermal.ACPI_CPPC.Efficient;
3522-
3523-
Core->PowerThermal.HWP_Capabilities.Lowest = \
3524-
Core->PowerThermal.ACPI_CPPC.Lowest;
3525-
3526-
Core->PowerThermal.HWP_Request.Minimum_Perf = \
3527-
Core->PowerThermal.ACPI_CPPC.Minimum;
3528-
3529-
Core->PowerThermal.HWP_Request.Maximum_Perf = \
3530-
Core->PowerThermal.ACPI_CPPC.Maximum;
3531-
3532-
Core->PowerThermal.HWP_Request.Desired_Perf = \
3533-
Core->PowerThermal.ACPI_CPPC.Desired;
3534-
3535-
Core->PowerThermal.HWP_Request.Energy_Pref = \
3536-
Core->PowerThermal.ACPI_CPPC.Energy;
3508+
Read_ACPI_CPPC_Registers(Core->Bind, NULL);
35373509

35383510
scaledFreq = Core->PowerThermal.ACPI_CPPC.Minimum
35393511
* Core->PowerThermal.ACPI_CPPC.Efficient;
@@ -3778,9 +3750,9 @@ static void Controller_Start(int wait)
37783750
&PRIVATE(OF(Core, AT(cpu)))->ThermalWork,
37793751
msecs_to_jiffies(PUBLIC(RO(Proc))->SleepInterval)
37803752
);
3781-
smp_call_function_single(cpu,
3782-
Arch[PUBLIC(RO(Proc))->ArchID].Start,
3783-
NULL, wait);
3753+
smp_call_on_cpu(cpu,
3754+
Arch[PUBLIC(RO(Proc))->ArchID].Start,
3755+
NULL, false);
37843756
}
37853757
}
37863758
}
@@ -3795,9 +3767,9 @@ static void Controller_Stop(int wait)
37953767
if ((BITVAL(PRIVATE(OF(Core, AT(cpu)))->Join.TSM, CREATED) == 1)
37963768
&& (BITVAL(PRIVATE(OF(Core, AT(cpu)))->Join.TSM, STARTED) == 1))
37973769
{
3798-
smp_call_function_single(cpu,
3799-
Arch[PUBLIC(RO(Proc))->ArchID].Stop,
3800-
NULL, wait);
3770+
smp_call_on_cpu(cpu,
3771+
Arch[PUBLIC(RO(Proc))->ArchID].Stop,
3772+
NULL, false);
38013773

38023774
cancel_delayed_work_sync(
38033775
&PRIVATE(OF(Core, AT(cpu)))->ThermalWork
@@ -4663,8 +4635,8 @@ static void (*Platform_Setup[])(CORE_RO*, union SAVE_AREA_CORE*) = {
46634635
[PFM_DGX_SPARK] = Setup_DGX_Spark_GX10
46644636
};
46654637

4666-
static void Start_GenericMachine(void *arg)
4667-
{
4638+
IMPL_SMP_FUNC(/*func:*/ Start_GenericMachine, /*body:*/ {
4639+
46684640
unsigned int cpu = smp_processor_id();
46694641
CORE_RO *Core = (CORE_RO *) PUBLIC(RO(Core, AT(cpu)));
46704642
union SAVE_AREA_CORE *Save = &PRIVATE(OF(Core, AT(cpu)))->SaveArea;
@@ -4690,10 +4662,10 @@ static void Start_GenericMachine(void *arg)
46904662
HRTIMER_MODE_REL_PINNED);
46914663

46924664
BITSET(LOCKLESS, PRIVATE(OF(Core, AT(cpu)))->Join.TSM, STARTED);
4693-
}
4665+
});
4666+
4667+
IMPL_SMP_FUNC(/*func:*/ Stop_GenericMachine, /*body:*/ {
46944668

4695-
static void Stop_GenericMachine(void *arg)
4696-
{
46974669
unsigned int cpu = smp_processor_id();
46984670
CORE_RO *Core = (CORE_RO *) PUBLIC(RO(Core, AT(cpu)));
46994671
union SAVE_AREA_CORE *Save = &PRIVATE(OF(Core, AT(cpu)))->SaveArea;
@@ -4714,7 +4686,7 @@ static void Stop_GenericMachine(void *arg)
47144686
PerCore_Reset(Core);
47154687

47164688
BITCLR(LOCKLESS, PRIVATE(OF(Core, AT(cpu)))->Join.TSM, STARTED);
4717-
}
4689+
});
47184690

47194691
static long Sys_OS_Driver_Query(void)
47204692
{
@@ -6515,9 +6487,9 @@ static int CoreFreqK_HotPlug_CPU_Online(unsigned int cpu)
65156487
&PRIVATE(OF(Core, AT(cpu)))->ThermalWork,
65166488
msecs_to_jiffies(PUBLIC(RO(Proc))->SleepInterval)
65176489
);
6518-
smp_call_function_single(cpu,
6519-
Arch[PUBLIC(RO(Proc))->ArchID].Start,
6520-
NULL, 0);
6490+
smp_call_on_cpu(cpu,
6491+
Arch[PUBLIC(RO(Proc))->ArchID].Start,
6492+
NULL, false);
65216493
}
65226494
}
65236495
#if defined(CONFIG_CPU_IDLE) && LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
@@ -6544,9 +6516,9 @@ static int CoreFreqK_HotPlug_CPU_Offline(unsigned int cpu)
65446516
if ((BITVAL(PRIVATE(OF(Core, AT(cpu)))->Join.TSM, CREATED) == 1)
65456517
&& (BITVAL(PRIVATE(OF(Core, AT(cpu)))->Join.TSM, STARTED) == 1)
65466518
&& (Arch[PUBLIC(RO(Proc))->ArchID].Stop != NULL)) {
6547-
smp_call_function_single(cpu,
6548-
Arch[PUBLIC(RO(Proc))->ArchID].Stop,
6549-
NULL, 1);
6519+
smp_call_on_cpu(cpu,
6520+
Arch[PUBLIC(RO(Proc))->ArchID].Stop,
6521+
NULL, false);
65506522

65516523
cancel_delayed_work_sync(&PRIVATE(OF(Core, AT(cpu)))->ThermalWork);
65526524
}
@@ -6571,15 +6543,15 @@ static int CoreFreqK_HotPlug_CPU_Offline(unsigned int cpu)
65716543
{
65726544
if ((BITVAL(PRIVATE(OF(Core, AT(alt)))->Join.TSM, STARTED) == 1)
65736545
&& (Arch[PUBLIC(RO(Proc))->ArchID].Stop != NULL)) {
6574-
smp_call_function_single(alt,
6575-
Arch[PUBLIC(RO(Proc))->ArchID].Stop,
6576-
NULL, 1);
6546+
smp_call_on_cpu(alt,
6547+
Arch[PUBLIC(RO(Proc))->ArchID].Stop,
6548+
NULL, false);
65776549
}
65786550
if ((BITVAL(PRIVATE(OF(Core, AT(alt)))->Join.TSM, STARTED) == 0)
65796551
&& (Arch[PUBLIC(RO(Proc))->ArchID].Start != NULL)) {
6580-
smp_call_function_single(alt,
6581-
Arch[PUBLIC(RO(Proc))->ArchID].Start,
6582-
NULL, 0);
6552+
smp_call_on_cpu(alt,
6553+
Arch[PUBLIC(RO(Proc))->ArchID].Start,
6554+
NULL, false);
65836555
}
65846556
}
65856557
}
@@ -7402,7 +7374,11 @@ static int CoreFreqK_Ignition_Level_Up(INIT_ARG *pArg)
74027374
}
74037375
#endif /* CONFIG_PM_OPP */
74047376
if (PUBLIC(RO(Proc))->Features.ACPI) {
7377+
CORE_RO *Core = PUBLIC( RO(Core,
7378+
AT(PUBLIC(RO(Proc))->Service.Core)) );
7379+
74057380
ReCompute_FactoryFrequency();
7381+
PerCore_Compute_ACPI_CPPC(Core);
74067382
}
74077383
#ifdef CONFIG_HOTPLUG_CPU
74087384
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)

aarch64/corefreqk.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,22 @@ typedef struct {
551551
void (*SetTarget)(void *arg);
552552
} SYSTEM_DRIVER;
553553

554+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
555+
#define PROT_SMP_FUNC(fn) int fn(void *arg)
556+
#else
557+
#define smp_call_on_cpu(cpu, fn, par, phys) work_on_cpu(cpu, fn, par)
558+
#define PROT_SMP_FUNC(fn) long fn(void *arg)
559+
#endif
560+
561+
#define DECL_SMP_FUNC(fn) static PROT_SMP_FUNC(fn)
562+
563+
#define IMPL_SMP_FUNC(fn, ...) \
564+
DECL_SMP_FUNC(fn) \
565+
{ \
566+
__VA_ARGS__ \
567+
return 0; \
568+
}
569+
554570
typedef struct {
555571
char **Brand;
556572
enum CODENAME CN;
@@ -561,8 +577,8 @@ typedef struct
561577
struct SIGNATURE Signature;
562578
void (*Query)(unsigned int cpu);
563579
void (*Update)(void *arg); /* Must be static */
564-
void (*Start)(void *arg); /* Must be static */
565-
void (*Stop)(void *arg); /* Must be static */
580+
PROT_SMP_FUNC( (*Start)); /* Must be static */
581+
PROT_SMP_FUNC( (*Stop)); /* Must be static */
566582
void (*Exit)(void);
567583
void (*Timer)(unsigned int cpu);
568584
CLOCK (*BaseClock)(unsigned int ratio);
@@ -586,8 +602,8 @@ typedef struct
586602
static CLOCK BaseClock_GenericMachine(unsigned int ratio) ;
587603
static void Query_GenericMachine(unsigned int cpu) ;
588604
static void PerCore_GenericMachine(void *arg) ;
589-
static void Start_GenericMachine(void *arg) ;
590-
static void Stop_GenericMachine(void *arg) ;
605+
DECL_SMP_FUNC(Start_GenericMachine) ;
606+
DECL_SMP_FUNC(Stop_GenericMachine) ;
591607
static void InitTimer_GenericMachine(unsigned int cpu) ;
592608
static void Query_DynamIQ(unsigned int cpu) ;
593609
static void Query_CoherentMesh(unsigned int cpu) ;

0 commit comments

Comments
 (0)