User:Lensovet/cs162 and 1st General Assembly of Nova Scotia: Difference between pages

From Wikipedia, the free encyclopedia
(Difference between pages)
Content deleted Content added
→‎System calls: pseudocode
 
 
Line 1: Line 1:
'''1st General Assembly of Nova Scotia''' represented [[Nova Scotia]] between [[October 2]], [[1758]] and [[December 4]], [[1759]], its membership being set in the [[1758 Nova Scotia general election]].
==File system calls==
===Implementation===
* New State Variables:
** <code>UserProcess.openFiles</code>: HashTable of file descriptor->(OpenFile, shouldDelete) tuples.
* <code>handleCreat</code>: This method calls <code>open()</code>. If <code>open()</code> returns -1, then we create a new file by associating a new unused file descriptor with a new OpenFile in the HashTable. Otherwise we return what <code>open()</code> returns, which is the file descriptor of the existing file. Bulletproofs against the following conditions:
** Name is null.
** Name exceeds 256 bytes.
* <code>handleOpen</code>: This method checks if the file name argument given is valid. If it is, we create a new instance of an <code>OpenFile</code> via <code>FileSystem.open()</code>. We insert the new OpenFile into the hashtable and return its index as its file descriptor. If .open() returned null, handle appropriately. Bulletproofs against the following conditions:
** Name is null.
** Name exceeds 256 bytes.
** Open() returns null.
* <code>handleRead</code>: This method first checks if fileDescriptor is invalid, if part of the buffer is read-only or invalid, or if a network stream has been terminated by the remote host and no more data is available. If the arguments are valid, it retrieves the file designated by the given fileDescriptor and we call .read() on the OpenFile instance returned by the hashtable. Bulletproofs against the following conditions:
** Invalid file descriptor.
** Read-only or invalid buffer.
** Stream has been terminated.
** Errors returned from .read().
* <code>handleWrite</code>: This method checks if <code>fileDescriptor</code> is invalid, if part of the buffer is invalid, or if a network stream has already been terminated by the remote host. Call .write() on the OpenFile instance associated with the file descriptor. Bulletproofs against the following conditions:
** Invalid file descriptor.
** Invalid buffer.
** Stream has been terminated.
** Errors returned from .write().
* <code>handleClose</code>: This method will remove the file descriptor from the HashTable of the calling process and call .close() on the OpenFile instance. Bulletproofs against the following conditions:
** Invalid file descriptor.
**
* <code>handleUnlink</code>: This method deletes a file given a file name. If there are no processes that currently have this file open, the file is deleted immediately. The file system implementation will handle deletion of files which are currently opened by processes. This method will perform checks on the argument before calling FileSystem.remove(). Bulletproofs against the following conditions:
** Name exceeds 256 bytes or is null.
** Invalid file name.


The Assembly sat at the pleasure of the [[Governor of Nova Scotia]], [[Charles Lawrence]]. [[Robert Sanderson]] was elected [[Speaker of the House of Assembly of Nova Scotia|speaker]] for the first session, [[William Nesbitt]] for the second.
===Pseudocode===


===Test cases===
==Division of seats==
*Create
**Create files with null names
**Create files with names longer than 256 bytes
**Make sure create on an existing file you get the right handler
**Create non-existent file with valid name, make sure it's actually created
*Open
**Open files with null names
**Open files with names longer than 256 bytes
**Make sure opening an existing file gets you the right handler (should be same as calling create with the same filename)
**Open non-existent file with valid name, make sure we return error
*Read
**Read files which have not been opened yet (i.e. invalid file descriptor)
**Read files into read-only buffers
**Read from terminated streams into legit buffer
**Verify that reading the correct files into legit buffers properly reads the necessary data into the buffer
*Write
**Write to files which have not been opened yet (i.e. invalid file descriptor)
**Write to files from bad buffers (null, 0-length?)
**Write to terminated streams from legit buffer
**Verify that writing the correct files from legit buffers properly writes the necessary data to the file. Verify that changes propagate to disk after .close()
*Close
**Close files which have not been opened yet (i.e. invalid file descriptor)
**Verify that closing correct files returns no errors and that unlinking afterwards actually removes the file.
*Unlink
**Unlink nonexistent files
**Unlink files with illegal filenames
**Unlink files not open by anyone else, verify that they are deleted from the system
**Unlink files open by someone else, verify that they remain on the filesystem but are deleted after .close() is called by the opened one.


The division of seats within the Nova Scotia Legislature after the General Election of 1758.
==Multiprogramming==
===Implementation===
* New State Variables:
**<code>freePages</code>: A LinkedList of free physical pages to handle the allocation of physical memory.
* We maintain a linked list of free physical pages to handle the allocation of physical memory. When a process allocated memory, pages are taken off the free list. When that process finishes execution, it puts the pages back onto the free list. All blocks of memory should be returned to the free list regardless of whether the exit is voluntary.
* On instantiation, the <code>UserKernel</code> creates a list of all available physical pages by calling <code>numPhysPages()</code>. Every time a UserProcess is instantiated and creates a TranslationEntry and removes it from the list of available physical pages. Whenever a process is terminated or finishes, the pages used by the process are put back on the UserKernel's list of available physical pages.
* <code>readVirtualMemory()</code>: This method will first look through its page table and find the actual physical address. We read the address for the value in memory and return the value.
* <code>writeVirtualMemory()</code>: The method also finds the actual physical address as in readVirtualMemory. It checks if it can write to this address and does so if it can.
* <code>loadSections()</code>: If numPages is greater than the number of available physical pages, return false. We first make numPages of TranslationEntries and put them into the page table. Before calling section.loadPage(), we look in our page table for the PPN corresponding to the given VPN. Then we call section.loadPage() with the PPN.


* [[Joseph Gerrish]]
===Pseudocode===
* Robert Sanderson
* [[Henry Newton (politician)|Henry Newton]]
* William Foye
* Wlliam Nesbitt
* Joseph Rundell
* [[Jonathan Binney]]
* Henry Ferguson
* [[George Suckling]]
* [[John Burbidge]]
* Robert Campbell
* William Pantree
* Joseph Fairbanks
* Philip Hammond
* [[John Fillis]]
* Lambert Folkers
* [[Philip Augustus Knaut|Philip Knaut]]
* [[William Best (Nova Scotia politician)|William Best]]
* Alexander Kedie


===Test cases===
==External links==
*[http://www.democracy250.ca/ Democracy 250 : Celebrating 250 Years of Parliamentary Democracy in Canada]
* Create several processes and make sure their memory spaces do not overlap.
** Use an algorithm to traverse all processes, and look at their page table entries. Make sure that each physical page is only referred to once.
* Test that the free list can assign non-contiguous blocks of memory to a single processes.
** Override the kernel's free memory list with out of order pages. Create several threads and confirm that their memory functions normally.
* Test that on both voluntary and involuntary exits free all blocks of memory.
** Create many threads and terminate them both normally and forcefully. Verify that all their memory has been freed by examining the free list both before and after the termination.


==System calls==
== ==
{{start box}}
===Implementation===
{{succession box| title=[[List of General Assemblies of Nova Scotia|General Assemblies of Nova Scotia]]|
*New State Variables:
before= No previous General Assembly |
** <code>UserProcess.processThreads</code>: HashTable of PID-><code>UThread</code> instances.
after=[[2nd General Assembly of Nova Scotia]] |
** <code>UserKernel.currentPID</code>: A global counter of PIDs. New processes will be instantiated with the current PID value and increment the counter.
years=1758-1759|
** <code>UserProcess.exitState</code>: NOTSTARTED or 0 (if exit() has already been called) or some other integer if handleException() was called
}}
** We assume that each process only has one thread associated with it. To access each process's thread, we have a hashtable of PID-><code>UThread</code> instances; <code>UserProcess</code> keeps track of its children.
{{end box}}
* <code>exec()</code>: This method creates a new user process with <code>UserProcess.newUserProcess()</code>. It initializes file descriptors 0 and 1. <code>.execute()</code> is called on the given file. Add parent process id var. Init it properly.
* <code>join()</code>: The thread of process A retrieves the UThread instance associated with the given process ID (thread B) via the hashtable. This method verifies that the joiner is actually parent process. Then it checks to see if the exitState of the owning process is not NOTSTARTED; if so, it returns the exitState immediately. Otherwise calls super.join() with Thread B.
* <code>exit()</code>: This method calls <code>close()</code> on all file descriptors. It puts all pages in page table into free list, wakes up joined threads, disowns all children processes, and sets the <code>exitState</code> var to some appropriate value. The last active process to call <code>exit()</code> calls <code>Kernel.kernel.terminate()</code> to halt the machine.


[[Category:Nova Scotia General Assemblies|01]]
===Pseudocode===
exec()
process = UserProcess.newUserProcess()
process.fileDescriptors.put(0, stdin)
process.fileDescriptors.put(1, stdout)
process.parentId = pId
process.execute()

UserProcess.join()
joinerproc = pids.get(join_process_id)
joinerproc.join()

UThread.join()
if (parentId != currentThread.process.pId)
return -1
if (process.exitState != NOTSTARTED)
return process.exitState
super.join()

===Test cases===
*join(): COPY FROM PROJ 1
** {{c|threadA}} prints out a few statements, calls {{c|threadB.join()}}, then prints out a few more statements. {{c|threadB}} also prints out a series of statements. We then verify that {{c|threadB}} executes contiguously to completion before {{c|threadA}} resumes its execution, as evidenced by the sequence of printed statements.
** Have a thread attempt to {{c|join()}} to itself, call {{c|join()}} on a second thread multiple times, and attempt to call {{c|join()}} on a third finished thread (all separately). These should all return immediately as this is the expected behavior.
** Test a chain of threads. Thread C will attempt to join Thread B. Thread B will attempt to join Thread A. Thread A forks last. Verify that A executes before B, and B executes before C.

==Lottery scheduler==
===Implementation===
* The holder of each <code>ThreadQueue</code> will keep track of the total number of lottery tickets held by its threads.
* When selecting the next thread, the scheduler will choose the lottery ticket by picking a random number between 1 and the total number of tickets. The scheduler will iterate through the <code>ThreadQueue</code> and calculate the appropriate thread to run next.
* <code>increasePriority()</code> now increments the number of tickets held by a thread by 1. Similarly, <code>decreasePriority()</code> decrements the number of tickets held by a thread by 1.
* Donating is implemented as it was in <code>PriorityScheduler</code>. The <code>effectiveTickets</code> (<code>effectivePriority</code>) of a thread is now the sum of its own tickets and the tickets of all the threads waiting on this thread.
* <code>getEffectiveTickets()</code> asks all the queues that correspond to the resources it currently holds for the total number of tickets for .... COPY AND PASTE FROM PROJ1 DESIGN DOC

===Pseudocode===

===Test cases===
COPY AND PASTE FROM PRIORITY SCHEDULER with perhaps a few minor changes
* Instantiate new threads and set their priorities in decreasing order. Have the threads state their priorities as they execute and verify that they were run in decreasing order according to their priorities.
* Verify donation works by creating a high priority thread and joining it to a low priority thread with a high priority thread already queued.
* Create complex set of interdependent threads and multiple locks, verify that execution order is correct.

==Questions==
* Does a UProcess only have one UThread? How do we sleep a process? Do we sleep all threads owned by a process or ..
*

Revision as of 10:38, 13 October 2008

1st General Assembly of Nova Scotia represented Nova Scotia between October 2, 1758 and December 4, 1759, its membership being set in the 1758 Nova Scotia general election.

The Assembly sat at the pleasure of the Governor of Nova Scotia, Charles Lawrence. Robert Sanderson was elected speaker for the first session, William Nesbitt for the second.

Division of seats

The division of seats within the Nova Scotia Legislature after the General Election of 1758.

External links

Preceded by
No previous General Assembly
General Assemblies of Nova Scotia
1758-1759
Succeeded by