add place-holder directory for the a3000 wd533c93 scsi controller implementation.
[AROS.git] / workbench / system / SysMon / processor.c
blob249c8e7ffcc8519b40f57561928150a98e23dfac
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
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"
18 #include "locale.h"
20 extern struct MUI_CustomClass *ProcessorGauge_CLASS;
21 extern struct MUI_CustomClass *ProcessorGraph_CLASS;
23 /* Processor information */
24 static IPTR processorcount;
25 APTR ProcessorBase;
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)
35 ProcessorGauge_CLASS;
36 #else
37 ProcessorGraph_CLASS;
38 #endif
39 smdata->cpuusagesinglemode =
40 #if defined(PROCDISPLAY_SINGLEGRAPH)
41 TRUE;
42 #else
43 FALSE;
44 #endif
47 #if SIMULATE_USAGE_FREQ
48 processorcount = 4;
49 return TRUE;
50 #else
51 ProcessorBase = OpenResource(PROCESSORNAME);
53 if (ProcessorBase)
55 struct TagItem tags [] =
57 { GCIT_NumberOfProcessors, (IPTR)&processorcount },
58 { 0, (IPTR)NULL }
61 GetCPUInfo(tags);
63 return TRUE;
66 return FALSE;
67 #endif
70 static VOID DeInitProcessor(struct SysMonData *smdata)
74 Object *ProcessorGroupObject(struct SysMonData *smdata, IPTR count)
76 Object *newGroupObj;
78 newGroupObj = NewObject(smdata->cpuusageclass->mcc_Class, NULL,
79 MUIA_ProcessorGrp_CPUCount, count,
80 MUIA_ProcessorGrp_SingleMode, (IPTR)smdata->cpuusagesinglemode,
81 TAG_DONE);
83 return newGroupObj;
86 ULONG GetProcessorCount()
88 return processorcount;
91 VOID UpdateProcessorInformation(struct SysMonData * smdata)
93 ULONG i;
94 TEXT buffer[128];
96 DoMethod(smdata->cpuusageobj, MUIM_ProcessorGrp_Update);
98 for (i = 0; i < processorcount; i++)
100 UQUAD frequency = 0;
101 #if SIMULATE_USAGE_FREQ
102 struct DateStamp ds;
103 DateStamp(&ds);
104 frequency = ((ds.ds_Tick * (i + 1)) % 100) * 10;
105 #else
106 struct TagItem tags [] =
108 { GCIT_SelectedProcessor, (IPTR)i },
109 { GCIT_ProcessorSpeed, (IPTR)&frequency },
110 { TAG_DONE, TAG_DONE }
113 GetCPUInfo(tags);
115 frequency /= 1000000;
116 #endif
117 __sprintf(buffer, "%d MHz", (ULONG)frequency);
118 set(smdata->cpufreqvalues[i], MUIA_Text_Contents, (IPTR)buffer);
122 VOID UpdateProcessorStaticInformation(struct SysMonData * smdata)
124 ULONG i;
125 TEXT buffer[172];
126 CONST_STRPTR modelstring;
128 for (i = 0; i < processorcount; i++)
130 #if SIMULATE_USAGE_FREQ
131 modelstring = _(MSG_SIMULATED_CPU);
132 #else
133 struct TagItem tags [] =
135 { GCIT_SelectedProcessor, (IPTR)i },
136 { GCIT_ModelString, (IPTR)&modelstring },
137 { TAG_DONE, TAG_DONE }
140 GetCPUInfo(tags);
141 #endif
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))
152 AROS_USERFUNC_INIT
154 struct SysMonData * smdata = h->h_Data;
155 IPTR cpuCount = 0;
156 Object *newGrp;
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;
177 AROS_USERFUNC_EXIT
180 AROS_UFH3(VOID, processorgraphhookfunc,
181 AROS_UFHA(struct Hook *, h, A0),
182 AROS_UFHA(Object *, object, A2),
183 AROS_UFHA(APTR, msg, A1))
185 AROS_USERFUNC_INIT
187 struct SysMonData * smdata = h->h_Data;
188 IPTR cpuCount = 0, graphMode = 0;
189 Object *newGrp;
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;
212 AROS_USERFUNC_EXIT
215 AROS_UFH3(VOID, processorgraphpercpuhookfunc,
216 AROS_UFHA(struct Hook *, h, A0),
217 AROS_UFHA(Object *, object, A2),
218 AROS_UFHA(APTR, msg, A1))
220 AROS_USERFUNC_INIT
221 IPTR cpuCount = 0, graphMode = 0;
222 Object *newGrp;
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;
247 AROS_USERFUNC_EXIT
252 struct SysMonModule processormodule =
254 .Init = InitProcessor,
255 .DeInit = DeInitProcessor,