OS Theme - Multitasking OS and more: Vitamin's thoughts.

ZX Time #13
 TOPIC >OS<               
 -----------              
                                        
 Multitasking OS and more      
 ------------------------------     
 (C) Vitamin/CAIG           
                                        
 Requires the use of displacement
multitasking.  The question arises: which
choose mode? Dependence of the work quantum
on priority or dependence of the total
time from priority?                  
                                        
 The first method is quite well implemented.
works, but has a number of disadvantages. Basic
van he on the fact that when the process is running
its counter decreases and as soon as it
reaches zero, the scheduler switches
work for another process.  There is
opportunity to voluntarily give your
time quantum for the next process. Dos-
touhctba:  + ease of implementation;               
 + ability to skip time;      
 + the process can determine how many
he still has to work until the process changes.
                                        
 Disadvantages:                          
 - there is no direct relationship between the
putetom and the frequency of the process.     
                                        
 In this case, use npuopute-
tov is very conditional. They simply mean
how long can the process be maximally
but work until it's gone
will interrupt the scheduler.                    
                                        
 This is quite unfair - pro-
a process with a lower priority can do more
boot the system, the higher the priority
ny.                                    
                                        
 Implementation of another option is possible
with absolute npuoputetamu. Ideathis
The method is this. There are two queues
processes - working and waiting. B per-
The second queue contains those processes that
some have not yet exhausted their time quantum
or were forced out.  In the second stage
lie those processes that have already been exhausted
their quantum or voluntarily gave it up
to another process.  In the simplest case
to distinguish process affiliation
to a particular queue you can use
set flag. As process parameters
sa are itspriority, the flag belongs
position and counter, values
which are compared when planning and
when reaching zero which, the process
forcibly goes into the waiting category
schi. A planning model was developed
to test this method. B models
"worked" 8 processes with different purposes
oputetamu and two types - "light" and
"heavy". "Easy" processes when received
CPU time is immediately assigned
solder it to the next process. "Heavy"
processes do not do this and are completely
take their time slice.           Параметры процессов           
      ---┬-----------┬----------        
       NПриоритет Тип            
      ---┼-----------┼----------        
       04    "легкий"         
       18     -"-            
       216     -"-            
       324     -"-            
       44    "тяжелый"        
       58     -"-            
       616     -"-            
       724     -"-            
      ---┴-----------┴----------        
                                        
01234567                                
--------                                
       7                                
   3   7 ;процесс  3 захватил процессор,
         ;т.к.  его счетчик больше чем y
         ;7-го                          
       7 ;и тут жеswitched to state  
 ;waiting                      
 7                               
 7                               
 7                               
 7                               
 7                               
 7                               
 6  ;capture by process 6           
 2 7 ;and process 2, which immediately left
 6  ;6 and 7 begin to compete  
 7                               
 6                                 
 7                               
 6        7                                
      6                                 
       7                                
      6                                 
       7                                
      6                                 
       7                                
      6                                 
       7 ;к конкурентам добавл.5 процесс
      6                                 
     5                                  
 1     7                                
      6                                 
     5                                  
       7        6                                 
     5                                  
       7                                
      6                                 
     5                                  
       7                                
      6                                 
     5                                  
    4                                   
0      7 ;отработал самый "легкий" проц.
      6  ;все "тяжелые" процессы конку- 
         ;рирyют за время               
     5                                  
    4                                   
       7                                
6                                 
     5                                  
    4                                   
       7                                
      6                                 
     5                                  
    4                                   
       7                                
      6                                 
     5                                  
    4                                   
                                        
   Далее  все  повторяется c начала. Пе-
риод   работы  при  таком  раскладе - 56
квантов,  т.e.  сумма приоритетов "тяжe-
лых"  процессов, увеличенных на единицу.
Слабым  местом  данного  метода является
более частое переключениеprocesses that
will inevitably lead to processor costs -
a lot of time for the scheduler to work. But
if you write the code correctly and optimally,
then these losses can be minimized,
because  on interrupts will still execute
threads are running, various system functions
etc.  For such an implementation it is sufficient
just arrange the process handles
in descending order of counters. In this
In this case, you can simplify the work by pre-
carefully calculating the time remaining
process to work before its place
the next one will take. When adding a new
process accordingly produce cor-
pektpupobky tables.                    
                                        
 Process hierarchy          
                                        
In first place is system pro-
process, which performs various ser-
hanging functions, for example, starting the required
dark applications. This process is
the ancestor of all processes in the system.       
                                        
 In second place are processes like
daemon.  They are also intended
to perform variousservice functions
tions.  They don't have windows, user about
may not be aware of their presence.
Example of use - control over non-
sanctioned activity process
Sov.The demon during the moments of its work
Retrieves the contents of the stacks of sleeping processes
and in the case of executing code in someone else’s computer,
The memory department raises the alarm. Control
memory access cannot be implemented,
because it is impossible to unambiguously determine c
What registers are used to read?
tion or recording.  Also these functions
there may be kernel integrity monitoring,
automatic removal of frozen applications
ny and the like.                    
                                        
 In third place is the process - referred to
lock. Selecting this process from
a special place is made for standardization purposes
tions.  This process has windows (like mi-
at least two).                           
                                        
In fourth place are applied
processes.                               
                                        
 Memory management           
                                        
 The following seems most suitable
memory organization.  The process takes
page in upper memory and can be allocated
give yourself blocks of lower memory (for glass
ka, residents, etc.). But sometimes it can
a situation arises that requires the creation
give a process that doesn't need much
amount of memory (eg daemon). B
in this case it is necessary to provide
the ability to create special processes
type that may be at the bottom
memory, but be registered as
full process.  This implementation
requires more complex planning functions
processes, because  must be taken into account
lack of data linkage to specific
addresses, which is easily implemented in countries
private placement of processes.            
                                        
 Working with drives          
                                        
 For full operation of the file system
topic requires the implementation of various
disk access levels.               
                                        
 Level one - hardware.  Real-
is implemented at the level of drivers that implement
lick various functions, directly
but related to the equipment. Thisreading/
recording to a specific location on the disk, identified
identificationmedia type,other functions.
                                        
 Level two - system.   Special
cial functions that allow by name
file to determine its location on
media and provide access to any
place in the file.                          
                                        
 Level three - software.  Basic
is based on the previous two levels. Not-
deal with this level mediocrely
application programs. Provide for them
provides transparent support for various
disk systems, working with files, etc.
                                        
 Features of the disk system      
                                        
 For floppy disks, in general, it is enough
TR-DOS. To implement a catalog system
themes you can useDirSys.For
large drives require another
system.  One option FAT24 has both
advantages and disadvantages:          
                                        
 + Compatibility with media from other
many platforms using MS-DOS;      
 + file fragmentation;               
 + Catalog system               
 + Support for large storage volumes
body;                                   
                                        
 - low system reliability;      
 - inconvenience of using long
paths in the system (memory consumption);        
                                        
 From here we can conclude that it is necessary
Difficulties in creating a new disk system.
II see this system as a hybridFATfor
MS-DOS and s5fb  forUnix. Main idea
that's the point. All data about files except them
names are stored at the beginning of the disk. Info-
tion about the location of the file (chain of secto-
ditch) is stored in the disk map, which
also located at the beginning of the disk. Except
this, at the beginning of the disk there is a root ca-
a log in which you can write several
to files. The structure of the system is represented by
so on.  The disk directory lists
only file names and their indexes in the table
face files. The catalog also presents-
in the form of a file with a special attribute-
volume that also stores file names
fishing and indices.  With this implementation we
we get a number of advantages:              
                                        
 + compactness of the system;              
 + ease of maintenance - no need
climb all over the disk in order to
calculate the amount of space occupied
or check the correctness of the distribution table
sector positions;                     
+ instead of a long path to the file, you can
just store its index;              
 + possible to implement multiple
connections, i.e. the same file can
can be assigned different names and it can-
can be described in various folders. When
In this case, it is necessary to implement a connection counter
Zey in which the number will be stored
files with such data. When deleting
file from some folder, the counter decreases
hesitating.  When the counter reaches zero,
the file is deleted and the space it occupies is
liberated.                            
                                        
 Calculate the space occupied by the system.
Let the disk have a capacity of 32 megabytes c
65536 sectors of 512 bytes.            
                                        
 Let the file description require 16
byte:                                  
                                        
 - flags =1               
 -creation time =6               
 - connection counter =1               
 - initial sector = 2               
 - length =3               
                                        
 If you do not use temporary stamps,
Well, then you can use 8 bytes. For
It will take 65536 files on disk
65536*16 = 1MB = 2048 sectors. Otherwise -
1024 sectors (without time).             
                                        
 Sector map. 2 bytes per element. B
Each element stores the following number:
th sector of this chain.  2*65536 =
131072 bytes = 256 sectors.             
                                        
 Root directory.  6256 files, 1 each
bytes will occupy 8 sectors.                 
                                        
 - name + extension =14              
 - index = 2              
                                        
 Total: 2312 (1288) sectors or 3.5%
(1.96%) from the entire disk                  
                                        
 For comparison: TR-DOS:  16 sectors
this is 0.625%  That is.  only 5 (2.5) times
more.                                 
                                        
 When implementing this system, you can
bring the path of any nesting into 2 bytes
those that address the file description in the table,
which will entail reducing the table
open files.                        
                                        
 To reduce the file table, you can
also in the sector storing general information
information about the disk, describe how much space is required
required for files and what is their maximum
certain quantity and, in accordance with this
change the position of the system components.
                                        
 - - -  Comments from DWT:          
 ---------------------          
                                        
 Interesting ideas that personally appeal to me
introduced for a short time into some semblance
shock :))). In particular, it made me gasp
mother part of the article Vitamin, concerning-
implementation of multitasking - carefully
thorough study and professional support
move. However, I would like to see it all
at work with my own eyes. In the meantime... I-
The meaning is ambiguous :).                     
                                        
 Regarding the file system - in theory
Personally, I like almost everything. The truth is here
in using TR-DOS' file
system I highly doubt it. Judge
themselves, 636+Chkb - not enough, it’s no secret,
that today's magnetic media resource is
lei (of which the lion's share is still
since five-inch floppy disks) practically
exhausted (I don't have disks younger than seven
years).  And 3'5" wheels are not very reliable
thanks to the policy of their manufacturers (for
a couple of months y me out of the box in 10 dis-
ket "survives"three or four). Investigator-
but, it is necessary to increase the storage capacity and
develop flexibility (organize at least
"bypass" bad sectors). It is possible, of course
but, come up with different "developments of TR-
DOS", but these will be only half measures...  
                                        
 We are waiting for the readers' verdict.             
                                        
 - - -                  
                                        

Share your thoughts about the article