2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
7 #include <aros/debug.h>
9 #include "sysmon_intern.h"
11 #include <proto/processor.h>
12 #include <resources/processor.h>
13 #include <proto/dos.h>
15 #include <clib/alib_protos.h>
17 #include "processor.h"
20 extern struct MUI_CustomClass
*ProcessorGauge_CLASS
;
21 extern struct MUI_CustomClass
*ProcessorGraph_CLASS
;
23 /* Processor information */
24 static IPTR processorcount
;
26 #define SIMULATE_USAGE_FREQ 0
28 /* Processor functions */
29 static BOOL
InitProcessor(struct SysMonData
*smdata
)
31 if (!smdata
->cpuusageclass
)
33 smdata
->cpuusageclass
=
34 #if defined(PROCDISPLAY_USEGAUGE)
39 smdata
->cpuusagesinglemode
=
40 #if defined(PROCDISPLAY_SINGLEGRAPH)
47 #if SIMULATE_USAGE_FREQ
51 ProcessorBase
= OpenResource(PROCESSORNAME
);
55 struct TagItem tags
[] =
57 { GCIT_NumberOfProcessors
, (IPTR
)&processorcount
},
70 static VOID
DeInitProcessor(struct SysMonData
*smdata
)
74 Object
*ProcessorGroupObject(struct SysMonData
*smdata
, IPTR count
)
78 newGroupObj
= NewObject(smdata
->cpuusageclass
->mcc_Class
, NULL
,
79 MUIA_ProcessorGrp_CPUCount
, count
,
80 MUIA_ProcessorGrp_SingleMode
, (IPTR
)smdata
->cpuusagesinglemode
,
86 ULONG
GetProcessorCount()
88 return processorcount
;
91 VOID
UpdateProcessorInformation(struct SysMonData
* smdata
)
96 DoMethod(smdata
->cpuusageobj
, MUIM_ProcessorGrp_Update
);
98 for (i
= 0; i
< processorcount
; i
++)
101 #if SIMULATE_USAGE_FREQ
104 frequency
= ((ds
.ds_Tick
* (i
+ 1)) % 100) * 10;
106 struct TagItem tags
[] =
108 { GCIT_SelectedProcessor
, (IPTR
)i
},
109 { GCIT_ProcessorSpeed
, (IPTR
)&frequency
},
110 { TAG_DONE
, TAG_DONE
}
115 frequency
/= 1000000;
117 __sprintf(buffer
, "%d MHz", (ULONG
)frequency
);
118 set(smdata
->cpufreqvalues
[i
], MUIA_Text_Contents
, (IPTR
)buffer
);
122 VOID
UpdateProcessorStaticInformation(struct SysMonData
* smdata
)
126 CONST_STRPTR modelstring
;
128 for (i
= 0; i
< processorcount
; i
++)
130 #if SIMULATE_USAGE_FREQ
131 modelstring
= _(MSG_SIMULATED_CPU
);
133 struct TagItem tags
[] =
135 { GCIT_SelectedProcessor
, (IPTR
)i
},
136 { GCIT_ModelString
, (IPTR
)&modelstring
},
137 { TAG_DONE
, TAG_DONE
}
142 __sprintf(buffer
, (STRPTR
)_(MSG_PROCESSOR
), i
+ 1, modelstring
);
143 set(smdata
->cpufreqlabels
[i
], MUIA_Text_Contents
, buffer
);
147 AROS_UFH3(VOID
, processorgaugehookfunc
,
148 AROS_UFHA(struct Hook
*, h
, A0
),
149 AROS_UFHA(Object
*, object
, A2
),
150 AROS_UFHA(APTR
, msg
, A1
))
154 struct SysMonData
* smdata
= h
->h_Data
;
158 D(bug("[SysMon:Processor] %s(0x%p)\n", __func__
, smdata
));
160 if (smdata
->cpuusageclass
!= ProcessorGauge_CLASS
)
162 smdata
->cpuusageclass
= ProcessorGauge_CLASS
;
163 GET(smdata
->cpuusageobj
, MUIA_ProcessorGrp_CPUCount
, &cpuCount
);
164 if ((newGrp
= ProcessorGroupObject(smdata
, cpuCount
)) != NULL
)
166 if (DoMethod(smdata
->cpuusagegroup
, MUIM_Group_InitChange
))
168 DoMethod(smdata
->cpuusagegroup
, OM_ADDMEMBER
, (IPTR
)newGrp
);
169 DoMethod(smdata
->cpuusagegroup
, OM_REMMEMBER
, (IPTR
)smdata
->cpuusageobj
);
170 DoMethod(smdata
->cpuusagegroup
, MUIM_Group_ExitChange
);
171 MUI_DisposeObject(smdata
->cpuusageobj
);
172 smdata
->cpuusageobj
= newGrp
;
180 AROS_UFH3(VOID
, processorgraphhookfunc
,
181 AROS_UFHA(struct Hook
*, h
, A0
),
182 AROS_UFHA(Object
*, object
, A2
),
183 AROS_UFHA(APTR
, msg
, A1
))
187 struct SysMonData
* smdata
= h
->h_Data
;
188 IPTR cpuCount
= 0, graphMode
= 0;
191 D(bug("[SysMon:Processor] %s(0x%p)\n", __func__
, smdata
));
193 GET(smdata
->cpuusageobj
, MUIA_ProcessorGrp_CPUCount
, &cpuCount
);
194 GET(smdata
->cpuusageobj
, MUIA_ProcessorGrp_SingleMode
, &graphMode
);
195 if ((smdata
->cpuusageclass
!= ProcessorGraph_CLASS
) || ((cpuCount
> 1) && (!graphMode
)))
197 smdata
->cpuusageclass
= ProcessorGraph_CLASS
;
198 smdata
->cpuusagesinglemode
= TRUE
;
199 if ((newGrp
= ProcessorGroupObject(smdata
, cpuCount
)) != NULL
)
201 if (DoMethod(smdata
->cpuusagegroup
, MUIM_Group_InitChange
))
203 DoMethod(smdata
->cpuusagegroup
, OM_ADDMEMBER
, (IPTR
)newGrp
);
204 DoMethod(smdata
->cpuusagegroup
, OM_REMMEMBER
, (IPTR
)smdata
->cpuusageobj
);
205 DoMethod(smdata
->cpuusagegroup
, MUIM_Group_ExitChange
);
206 MUI_DisposeObject(smdata
->cpuusageobj
);
207 smdata
->cpuusageobj
= newGrp
;
215 AROS_UFH3(VOID
, processorgraphpercpuhookfunc
,
216 AROS_UFHA(struct Hook
*, h
, A0
),
217 AROS_UFHA(Object
*, object
, A2
),
218 AROS_UFHA(APTR
, msg
, A1
))
221 IPTR cpuCount
= 0, graphMode
= 0;
224 struct SysMonData
* smdata
= h
->h_Data
;
226 D(bug("[SysMon:Processor] %s(0x%p)\n", __func__
, smdata
));
228 GET(smdata
->cpuusageobj
, MUIA_ProcessorGrp_CPUCount
, &cpuCount
);
229 GET(smdata
->cpuusageobj
, MUIA_ProcessorGrp_SingleMode
, &graphMode
);
230 if ((smdata
->cpuusageclass
!= ProcessorGraph_CLASS
) || (graphMode
))
232 smdata
->cpuusageclass
= ProcessorGraph_CLASS
;
233 smdata
->cpuusagesinglemode
= FALSE
;
234 if ((newGrp
= ProcessorGroupObject(smdata
, cpuCount
)) != NULL
)
236 if (DoMethod(smdata
->cpuusagegroup
, MUIM_Group_InitChange
))
238 DoMethod(smdata
->cpuusagegroup
, OM_ADDMEMBER
, (IPTR
)newGrp
);
239 DoMethod(smdata
->cpuusagegroup
, OM_REMMEMBER
, (IPTR
)smdata
->cpuusageobj
);
240 DoMethod(smdata
->cpuusagegroup
, MUIM_Group_ExitChange
);
241 MUI_DisposeObject(smdata
->cpuusageobj
);
242 smdata
->cpuusageobj
= newGrp
;
252 struct SysMonModule processormodule
=
254 .Init
= InitProcessor
,
255 .DeInit
= DeInitProcessor
,