Skip to content

Commit

Permalink
[CR][AArch64] Backport the __GLIBC__ directive
Browse files Browse the repository at this point in the history
  • Loading branch information
cyring committed Feb 4, 2024
1 parent 63b893e commit ed59a8c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions aarch64/corefreq-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -9285,7 +9285,11 @@ Window *PopUpMessage(ASCII *title, RING_CTRL *pCtrl)

if (pCtrl->drc < RC_DRIVER_BASE)
{
#ifdef __GLIBC__
sysMsg = strerror_r(pCtrl->drc, inStr, POPUP_ALLOC);
#else
sysMsg = strerror(pCtrl->drc);
#endif
switch ( GET_LOCALE() ) {
case LOC_FR: /* Convert the System message to locale */
ISO_8859_To_Unicode((ASCII *) sysMsg, (ASCII *) inStr);
Expand Down
4 changes: 4 additions & 0 deletions aarch64/corefreq-ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,11 @@ void _LOCALE_IN(void)
SysLoc = newlocale(LC_MESSAGES_MASK, "", (locale_t) 0);

if (SysLoc != NULL) {
#ifdef __GLIBC__
const char *s18n = SysLoc->__names[5];
#else
const char *s18n = "en_US.UTF-8";
#endif
struct LOCALE_LOOKUP *lookUp = LocaleLookUp;
while (lookUp->i18n != NULL) {
I18N *i18n = lookUp->i18n;
Expand Down
7 changes: 7 additions & 0 deletions aarch64/corefreq.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,18 @@ typedef struct

unsigned long long Error;

#ifdef __GLIBC__
struct {
struct random_data data;
char state[128];
int value[2];
} Random;
#else
struct {
char state[128];
int value[2];
} Random;
#endif /* __GLIBC__ */

struct {
unsigned long long inside,
Expand Down
13 changes: 12 additions & 1 deletion aarch64/corefreqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,12 @@ void SliceScheduling( RO(SHM_STRUCT) *RO(Shm),
break;
case RAND_SMT:
do {
#ifdef __GLIBC__
if (random_r(&RO(Shm)->Cpu[cpu].Slice.Random.data,
&RO(Shm)->Cpu[cpu].Slice.Random.value[0]) == 0)
#else
RO(Shm)->Cpu[cpu].Slice.Random.value[0] = (int) random();
#endif /* __GLIBC__ */
{
seek = RO(Shm)->Cpu[cpu].Slice.Random.value[0]
% RO(Shm)->Proc.CPU.Count;
Expand Down Expand Up @@ -1563,7 +1567,11 @@ REASON_CODE Core_Manager(REF *Ref)
unsigned int cpu = 0;

pthread_t tid = pthread_self();
#ifdef __GLIBC__
RO(Shm)->App.Svr = tid;
#else
RO(Shm)->App.Svr = getpid();
#endif

if (ServerFollowService(&localService, &RO(Shm)->Proc.Service, tid) == 0) {
pthread_setname_np(tid, "corefreqd-pmgr");
Expand Down Expand Up @@ -1977,11 +1985,14 @@ REASON_CODE Child_Manager(REF *Ref)
:
:
);
#ifdef __GLIBC__
initstate_r( seed32,
RO(Shm)->Cpu[cpu].Slice.Random.state,
sizeof(RO(Shm)->Cpu[cpu].Slice.Random.state),
&RO(Shm)->Cpu[cpu].Slice.Random.data );

#else
initstate(seed32, RO(Shm)->Cpu[cpu].Slice.Random.state, 128);
#endif
if (!Arg[cpu].TID) {
/* Add this child thread. */
Arg[cpu].Ref = Ref;
Expand Down
6 changes: 5 additions & 1 deletion aarch64/corefreqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,15 @@ void Slice_Monte_Carlo(RO(SHM_STRUCT) *RO(Shm), RW(SHM_STRUCT) *RW(Shm),
{
double X, Y, Z;
UNUSED(arg);

#ifdef __GLIBC__
if (!random_r( &RO(Shm)->Cpu[cpu].Slice.Random.data,
&RO(Shm)->Cpu[cpu].Slice.Random.value[0] )
&& !random_r( &RO(Shm)->Cpu[cpu].Slice.Random.data,
&RO(Shm)->Cpu[cpu].Slice.Random.value[1] ))
#else
RO(Shm)->Cpu[cpu].Slice.Random.value[0] = (int) random();
RO(Shm)->Cpu[cpu].Slice.Random.value[1] = (int) random();
#endif /* __GLIBC__ */
{
X = (double) RO(Shm)->Cpu[cpu].Slice.Random.value[0] / RAND_MAX;
Y = (double) RO(Shm)->Cpu[cpu].Slice.Random.value[1] / RAND_MAX;
Expand Down

0 comments on commit ed59a8c

Please sign in to comment.