Skip to content

Commit

Permalink
[AArch64] Improving computation of Euclidean division
Browse files Browse the repository at this point in the history
  • Loading branch information
cyring committed Jul 9, 2024
1 parent c0367b9 commit c07a2e2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion aarch64/corefreq-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ typedef struct

COF_ST Boost[BOOST(SIZE)];

COF_UNION Ratio;
COF_ST Ratio;
} CORE_RO;

typedef struct
Expand Down
11 changes: 6 additions & 5 deletions aarch64/corefreq-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ TGrid *PrintRatioFreq( Window *win,

if ((( pRatio->Q > 0 || pRatio->R > 0 ) && !zerobase) || (zerobase))
{
double Freq_MHz=ABS_FREQ_MHz(double,pRatio->Q,CFlop->Clock) + pRatio->R;
const COF_ST COF = (*pRatio);
const double Freq_MHz = CLOCK_MHz(double, COF2FLOAT(COF) * CFlop->Clock.Hz);

if ((Freq_MHz > 0.0) && (Freq_MHz < CLOCK_MHz(double, UNIT_GHz(10.0))))
{
Expand Down Expand Up @@ -1071,7 +1072,7 @@ void RefreshTopFreq(TGrid *grid, DATA_TYPE data[])
!RO(Shm)->Cpu[top].Toggle
];
RefreshItemFreq(grid, COF.Q,
ABS_FREQ_MHz(double, COF.Q, CFlop->Clock) + COF.R);
CLOCK_MHz(double, COF2FLOAT(COF) * CFlop->Clock.Hz));
}

void RefreshPrimaryFreq(TGrid *grid, DATA_TYPE data[])
Expand All @@ -1087,7 +1088,7 @@ void RefreshPrimaryFreq(TGrid *grid, DATA_TYPE data[])
].Toggle
];
RefreshItemFreq(grid, COF.Q,
ABS_FREQ_MHz(double, COF.Q, CFlop->Clock) + COF.R);
CLOCK_MHz(double, COF2FLOAT(COF) * CFlop->Clock.Hz));
}

void RefreshHybridFreq(TGrid *grid, DATA_TYPE data[])
Expand All @@ -1103,7 +1104,7 @@ void RefreshHybridFreq(TGrid *grid, DATA_TYPE data[])
].Toggle
];
RefreshItemFreq(grid, COF.Q,
ABS_FREQ_MHz(double, COF.Q, CFlop->Clock) + COF.R);
CLOCK_MHz(double, COF2FLOAT(COF) * CFlop->Clock.Hz));
}

void RefreshConfigTDP(TGrid *grid, DATA_TYPE data[])
Expand Down Expand Up @@ -8204,7 +8205,7 @@ void Pkg_Fmt_Freq( ASCII *item, ASCII *code, CLOCK *clock,
} else {
StrFormat(item, RSZ(CREATE_SELECT_FREQ_OFFLINE)+9+10+1,
"%s" "%7.2f MHz %c%4u %c ",
code, ABS_FREQ_MHz(double, ratio.Q, (*clock)),
code, CLOCK_MHz(double, COF2FLOAT(ratio) * clock->Hz),
unlock ? '<' : '[', ratio.Q, unlock ? '>' : ']');
}
}
Expand Down
5 changes: 5 additions & 0 deletions aarch64/corefreq.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,8 @@ typedef struct {
time(&now); \
now - ref; \
})

#define COF2FLOAT(_COF) \
( \
(double)_COF.Q + (double)_COF.R / UNIT_KHz(PRECISION) \
)
6 changes: 2 additions & 4 deletions aarch64/corefreqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,9 @@ static void *Core_Cycle(void *arg)

const double FSF = UNIT_KHz(1.0)
/ ( (double)(RO(Shm)->Sleep.Interval * CFlip->Clock.Hz)
* ( (double)Cpu->Boost[BOOST(MAX)].Q
+ (double)Cpu->Boost[BOOST(MAX)].R / PRECISION ) );
* COF2FLOAT(Cpu->Boost[BOOST(MAX)]) );

CFlip->Absolute.Ratio.Perf = (double)RO(Core)->Ratio.COF.Q;
CFlip->Absolute.Ratio.Perf +=(double)RO(Core)->Ratio.COF.R / PRECISION;
CFlip->Absolute.Ratio.Perf = COF2FLOAT(RO(Core)->Ratio);

/* Compute IPS=Instructions per Hz */
CFlip->State.IPS = (double)CFlip->Delta.INST * FSF;
Expand Down
22 changes: 11 additions & 11 deletions aarch64/corefreqk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3295,23 +3295,23 @@ static void Generic_Core_Counters_Clear(union SAVE_AREA_CORE *Save,
})

#ifdef CONFIG_CPU_FREQ
inline COF_UNION Compute_COF_From_CPU_Freq(struct cpufreq_policy *pFreqPolicy)
inline COF_ST Compute_COF_From_CPU_Freq(struct cpufreq_policy *pFreqPolicy)
{
COF_UNION ratio;
FREQ2COF(pFreqPolicy->cur, ratio.COF);
COF_ST ratio;
FREQ2COF(pFreqPolicy->cur, ratio);
return ratio;
}
#endif /* CONFIG_CPU_FREQ */

inline COF_UNION Compute_COF_From_PMU_Counter( unsigned long long deltaCounter,
inline COF_ST Compute_COF_From_PMU_Counter( unsigned long long deltaCounter,
CLOCK clk,
COF_ST lowestRatio )
{
COF_UNION ratio;
COF_ST ratio;
deltaCounter /= PUBLIC(RO(Proc))->SleepInterval;
FREQ2COF(deltaCounter, ratio.COF);
if (ratio.COF.Q < lowestRatio.Q) {
ratio.COF = lowestRatio;
FREQ2COF(deltaCounter, ratio);
if (ratio.Q < lowestRatio.Q) {
ratio = lowestRatio;
}
return ratio;
}
Expand Down Expand Up @@ -3379,12 +3379,12 @@ static enum hrtimer_restart Cycle_GenericMachine(struct hrtimer *pTimer)
Core->Clock,
Core->Boost[BOOST(MIN)]);
#endif
PUBLIC(RO(Core, AT(cpu)))->Boost[BOOST(TGT)].Q = Core->Ratio.COF.Q;
PUBLIC(RO(Core, AT(cpu)))->Boost[BOOST(TGT)].R = Core->Ratio.COF.R;
PUBLIC(RO(Core, AT(cpu)))->Boost[BOOST(TGT)].Q = Core->Ratio.Q;
PUBLIC(RO(Core, AT(cpu)))->Boost[BOOST(TGT)].R = Core->Ratio.R;

#ifdef CONFIG_PM_OPP
{
enum RATIO_BOOST index = Find_OPP_From_Ratio(Core, Core->Ratio.COF.Q);
enum RATIO_BOOST index = Find_OPP_From_Ratio(Core, Core->Ratio.Q);

switch (SCOPE_OF_FORMULA(PUBLIC(RO(Proc))->voltageFormula)) {
case FORMULA_SCOPE_CORE:
Expand Down
3 changes: 1 addition & 2 deletions aarch64/corefreqk.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ struct SMBIOS17
#define FREQ2COF(_frequency, _COF) \
({ \
_COF.Q = (_frequency) / UNIT_KHz(PRECISION), \
_COF.R = CLOCK_KHz(unsigned short, \
(_frequency) - (_COF.Q * UNIT_KHz(PRECISION))); \
_COF.R = (_frequency) - (_COF.Q * UNIT_KHz(PRECISION)); \
})

#if !defined(RHEL_MAJOR)
Expand Down
9 changes: 2 additions & 7 deletions aarch64/coretypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,10 @@ enum OFFLINE

typedef struct
{
unsigned short Q,
R;
unsigned int Q : 8-0,
R : 32-8;
} COF_ST;

typedef union {
unsigned int Perf; /* STATUS or BOOST P-State */
COF_ST COF;
} COF_UNION;

typedef struct
{
unsigned long long Q,
Expand Down

0 comments on commit c07a2e2

Please sign in to comment.