1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
<refentry id="VisualOS-Processor-Algorithms">
<refmeta>
<refentrytitle>Processor Algorithms</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>VISUALOS Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Processor Algorithms</refname><refpurpose>Interface for Algorithms.</refpurpose>
</refnamediv>
<refsynopsisdiv><title>Synopsis</title>
<synopsis>
typedef <link linkend="cpu-algorithm-t">cpu_algorithm_t</link>;
<link linkend="cpu-algorithm-t">cpu_algorithm_t</link>* <link linkend="get-CPU-current-algorithm">get_CPU_current_algorithm</link> (void);
<link linkend="GSList">GSList</link>* <link linkend="init-CPU-algorithms">init_CPU_algorithms</link> (void);
<link linkend="gint">gint</link> <link linkend="register-CPU-algorithm">register_CPU_algorithm</link> (<link linkend="cpu-algorithm-t">cpu_algorithm_t</link> *algorithm);
<link linkend="gint">gint</link> <link linkend="deallocate-algorithm-private-data">deallocate_algorithm_private_data</link>
(<link linkend="proc-queue-t">proc_queue_t</link> proc_list);
<link linkend="gint">gint</link> <link linkend="set-CPU-heart-beat">set_CPU_heart_beat</link> (<link linkend="gint">gint</link> freq);
<link linkend="gint">gint</link> <link linkend="reset-CPU-timer">reset_CPU_timer</link> (void);
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
Great effort has been devoted to making the addicion of new algorithms as easy
as posible, here is documented what there is to know to be able to write your
own algorithms.
</para>
</refsect1>
<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="cpu-algorithm-t">cpu_algorithm_t</title>
<programlisting>typedef struct { /*This struct is all that we know about each algorithm*/
gchar * name;
gint (*select) (void);
gint (*unselect) (void); /* These two functions will be
called before and after the
use of an algorithm to let
it keep a low memory usage
when not in use.*/
gint (*clock) (void); /* timer interrupt. */
gint (*select_proc) (proc_t *proc); /* notifies the algorithm of a
process selection by the
user */
GtkWidget * process_properties;
GtkWidget * properties; /* Each algorithm will maintain
it's own properties widgets.
NULL means "no properties".
They should be set to NULL
when destroyed. If not
destroyed in "unselect" the
system will destroy them.*/
gint (*init_proc) (proc_t *proc); /* This function should allocate
and initialice algorith data
and anything else to get
a new process going, like
sticking it into a queue. */
gint (*end_proc) (proc_t *proc); /* This function should free the
algorithm specific data of
proc but should not take it
out of its queue */
gint (*event) (proc_t *proc); /* This function is called when
ever a process gets waked up
by an event and we have to
put it in some queue. */
gint (*next) (proc_t *proc); /* This function is called when
ever the current process gets
suspended waiting for some
event and we have to choose
another one to run.
It receives the suspended
process as argument just in
case its needed. */
} cpu_algorithm_t;
</programlisting>
<para>
</para></refsect2>
<refsect2>
<title><anchor id="get-CPU-current-algorithm">get_CPU_current_algorithm ()</title>
<programlisting><link linkend="cpu-algorithm-t">cpu_algorithm_t</link>* get_CPU_current_algorithm (void);</programlisting>
<para>
Find out which is the current algorithm.</para>
<para>
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> the struct which descrives the current algorithm.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="init-CPU-algorithms">init_CPU_algorithms ()</title>
<programlisting><link linkend="GSList">GSList</link>* init_CPU_algorithms (void);</programlisting>
<para>
Initializes the CPU algorithms code.
</para>
<para>
Mainly will call init functions for each algorithm.</para>
<para>
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> a pointer to the algorithm structs linked list
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="register-CPU-algorithm">register_CPU_algorithm ()</title>
<programlisting><link linkend="gint">gint</link> register_CPU_algorithm (<link linkend="cpu-algorithm-t">cpu_algorithm_t</link> *algorithm);</programlisting>
<para>
Each algorithm should call this function in it's initialization function
to register its algorithm struct.</para>
<para>
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>algorithm</parameter> :</entry>
<entry> algorithm struct to register.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> nothing important.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="deallocate-algorithm-private-data">deallocate_algorithm_private_data ()</title>
<programlisting><link linkend="gint">gint</link> deallocate_algorithm_private_data
(<link linkend="proc-queue-t">proc_queue_t</link> proc_list);</programlisting>
<para>
This function uses the algorithm's private data of each process
as argument to g_free.
</para>
<para>
This is for convinience of algorithm writers.</para>
<para>
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>proc_list</parameter> :</entry>
<entry> queue of processes.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> nothing important.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="set-CPU-heart-beat">set_CPU_heart_beat ()</title>
<programlisting><link linkend="gint">gint</link> set_CPU_heart_beat (<link linkend="gint">gint</link> freq);</programlisting>
<para>
Set timer interrupt frequency. Which means, the calling frequency
of algorithm function <parameter>clock</parameter>.
</para>
<para>
Zero means that the timer interupt is not desired.</para>
<para>
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>freq</parameter> :</entry>
<entry> new frequency in "time units".
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> nothing important.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="reset-CPU-timer">reset_CPU_timer ()</title>
<programlisting><link linkend="gint">gint</link> reset_CPU_timer (void);</programlisting>
<para>
Resets the "time unit" counter so we will have a full timeslice until
the next interupt.</para>
<para>
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> nothing important.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<variablelist>
<varlistentry>
<term><link linkend="Process">Process</link> Queues</term>
<listitem><para>How to inspect process queues.</para></listitem>
</varlistentry>
<varlistentry>
<term><link linkend="Processor">Processor</link> Simulation</term>
<listitem><para>How simulation works.</para></listitem>
</varlistentry>
<varlistentry>
<term><link linkend="Property">Property</link> Widget Facility</term>
<listitem><para>How to hadle numerical algorithm properties with the user
without learning GTK+.
</para></listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
</refentry>
|