From d4b94b9b478d03f3930f261d46e6bdf50d6b77e7 Mon Sep 17 00:00:00 2001 From: chyyuu Date: Sun, 30 Sep 2012 21:55:12 +0800 Subject: [PATCH 1/7] Update README --- README | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README b/README index cccd702..808b862 100644 --- a/README +++ b/README @@ -20,6 +20,25 @@ lab6: scheduling lab7: mutex/sync lab8: filesystem +If you don't want to install ubuntu and other softs to finish these labs, you can use VirtualBox soft (https://www.virtualbox.org/) and +a virtual disk image with all these softs. +You can download this virtual disk image -- oslabs_for_student_2012.zip (576.2MB,) from http://pan.baidu.com/share/link?shareid=69868&uk=2585194235, which +is an VirtualBox disk image (contains ubuntu 12.04 and needed softs, and is zipped with zip and xz format), and can be unzipped +by haozip software (http://www.haozip.com). +After unzip oslabs_for_student_2012.zip, you will get +--- +C:\vms\ubuntu-12.04.vbox.xz +C:\vms\ubuntu-12.04.vmdk.vmdk.xz +C:\vms\ubuntu-12.04.vmdk-flat.vmdk.xz +--- +then you will continue unzip all these files, and get +--- +C:\vms\ubuntu-12.04.vbox +C:\vms\ubuntu-12.04.vmdk.vmdk +C:\vms\ubuntu-12.04.vmdk-flat.vmdk +--- +If you installed VirtualBox soft, then the last step is: double clik file "ubuntu-12.04.vbox" and run ubuntu 12.04 in VirtualBox. + EXERCISE STEPS -------------- 1 $cd labX From 795c44d87ec9e746f1dbb6e6db8edd58716ddf9e Mon Sep 17 00:00:00 2001 From: chyyuu Date: Sun, 30 Sep 2012 21:56:28 +0800 Subject: [PATCH 2/7] Update README --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 808b862..4cee46e 100644 --- a/README +++ b/README @@ -20,7 +20,7 @@ lab6: scheduling lab7: mutex/sync lab8: filesystem -If you don't want to install ubuntu and other softs to finish these labs, you can use VirtualBox soft (https://www.virtualbox.org/) and +If you don't want to install ubuntu and other softs to finish these labs in Windows or MAC OS X, you can use VirtualBox soft (https://www.virtualbox.org/) and a virtual disk image with all these softs. You can download this virtual disk image -- oslabs_for_student_2012.zip (576.2MB,) from http://pan.baidu.com/share/link?shareid=69868&uk=2585194235, which is an VirtualBox disk image (contains ubuntu 12.04 and needed softs, and is zipped with zip and xz format), and can be unzipped From ede650a48836c498589eadde9616fdc28e941a5a Mon Sep 17 00:00:00 2001 From: chyyuu Date: Sun, 30 Sep 2012 21:57:57 +0800 Subject: [PATCH 3/7] Update README --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 4cee46e..2ca208c 100644 --- a/README +++ b/README @@ -20,8 +20,8 @@ lab6: scheduling lab7: mutex/sync lab8: filesystem -If you don't want to install ubuntu and other softs to finish these labs in Windows or MAC OS X, you can use VirtualBox soft (https://www.virtualbox.org/) and -a virtual disk image with all these softs. +If you don't want to install ubuntu and other softs to finish these labs in Windows, you can use VirtualBox soft (https://www.virtualbox.org/) and +a virtual disk image with all these softs. Below example is shown how to setup lab environment in Windows. You can download this virtual disk image -- oslabs_for_student_2012.zip (576.2MB,) from http://pan.baidu.com/share/link?shareid=69868&uk=2585194235, which is an VirtualBox disk image (contains ubuntu 12.04 and needed softs, and is zipped with zip and xz format), and can be unzipped by haozip software (http://www.haozip.com). From 0921d79644f455e882b2cbde9cb5cb18b000f067 Mon Sep 17 00:00:00 2001 From: chyyuu Date: Sun, 30 Sep 2012 22:01:59 +0800 Subject: [PATCH 4/7] Update README --- README | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README b/README index 2ca208c..9ad5572 100644 --- a/README +++ b/README @@ -37,7 +37,12 @@ C:\vms\ubuntu-12.04.vbox C:\vms\ubuntu-12.04.vmdk.vmdk C:\vms\ubuntu-12.04.vmdk-flat.vmdk --- -If you installed VirtualBox soft, then the last step is: double clik file "ubuntu-12.04.vbox" and run ubuntu 12.04 in VirtualBox. +If you installed VirtualBox soft, then the last step is: double clik file "ubuntu-12.04.vbox" and run ubuntu 12.04 in VirtualBox. +In ubuntu 12.04 login Interface: +username: chy +password: + +After you login, you will see the directory ucore_lab in HOME directory. EXERCISE STEPS -------------- From caeaa7e8c73e353eaf5309cdce5c56ff5fbef8fa Mon Sep 17 00:00:00 2001 From: chyyuu Date: Mon, 1 Oct 2012 21:26:19 +0800 Subject: [PATCH 5/7] update atomic.h and add .gitignore --- .gitignore | 3 +++ code/lab5/libs/atomic.h | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e6094c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +obj/ +bin/ diff --git a/code/lab5/libs/atomic.h b/code/lab5/libs/atomic.h index 958be2e..e8f317b 100644 --- a/code/lab5/libs/atomic.h +++ b/code/lab5/libs/atomic.h @@ -53,5 +53,29 @@ test_bit(int nr, volatile void *addr) { return oldbit != 0; } +/* * + * test_and_set_bit - Atomically set a bit and return its old value + * @nr: the bit to set + * @addr: the address to count from + * */ +static inline bool +test_and_set_bit(int nr, volatile void *addr) { + int oldbit; + asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory"); + return oldbit != 0; +} + +/* * + * test_and_clear_bit - Atomically clear a bit and return its old value + * @nr: the bit to clear + * @addr: the address to count from + * */ +static inline bool +test_and_clear_bit(int nr, volatile void *addr) { + int oldbit; + asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory"); + return oldbit != 0; +} + #endif /* !__LIBS_ATOMIC_H__ */ From 6a1b22578e95e76fceeb7fcd09aa2e86be9e60cf Mon Sep 17 00:00:00 2001 From: chyyuu Date: Mon, 1 Oct 2012 21:49:27 +0800 Subject: [PATCH 6/7] update atomic.h in lab6 --- code/lab6/libs/atomic.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/lab6/libs/atomic.h b/code/lab6/libs/atomic.h index 958be2e..e8f317b 100644 --- a/code/lab6/libs/atomic.h +++ b/code/lab6/libs/atomic.h @@ -53,5 +53,29 @@ test_bit(int nr, volatile void *addr) { return oldbit != 0; } +/* * + * test_and_set_bit - Atomically set a bit and return its old value + * @nr: the bit to set + * @addr: the address to count from + * */ +static inline bool +test_and_set_bit(int nr, volatile void *addr) { + int oldbit; + asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory"); + return oldbit != 0; +} + +/* * + * test_and_clear_bit - Atomically clear a bit and return its old value + * @nr: the bit to clear + * @addr: the address to count from + * */ +static inline bool +test_and_clear_bit(int nr, volatile void *addr) { + int oldbit; + asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory"); + return oldbit != 0; +} + #endif /* !__LIBS_ATOMIC_H__ */ From a0b91ae23feca871108a8187022d0455a1b2d2c2 Mon Sep 17 00:00:00 2001 From: chyyuu Date: Mon, 1 Oct 2012 22:21:31 +0800 Subject: [PATCH 7/7] Page struct related info in update memlayout.h --- code/lab2/kern/mm/memlayout.h | 4 ++-- code/lab3/kern/mm/memlayout.h | 4 ++-- code/lab4/kern/mm/memlayout.h | 7 +++---- code/lab5/kern/mm/memlayout.h | 7 +++---- code/lab6/kern/mm/memlayout.h | 7 +++---- code/lab7/kern/mm/memlayout.h | 7 +++---- code/lab8/kern/mm/memlayout.h | 7 +++---- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/code/lab2/kern/mm/memlayout.h b/code/lab2/kern/mm/memlayout.h index 12af91c..1e58466 100644 --- a/code/lab2/kern/mm/memlayout.h +++ b/code/lab2/kern/mm/memlayout.h @@ -104,8 +104,8 @@ struct Page { }; /* Flags describing the status of a page frame */ -#define PG_reserved 0 // the page descriptor is reserved for kernel or unusable -#define PG_property 1 // the member 'property' is valid +#define PG_reserved 0 // if this bit=1: the Page is reserved for kernel, cannot be used in alloc/free_pages; otherwise, this bit=0 +#define PG_property 1 // if this bit=1: the Page is the head page of a free memory block(contains some continuous_addrress pages), and can be used in alloc_pages; if this bit=0: if the Page is the the head page of a free memory block, then this Page and the memory block is alloced. Or this Page isn't the head page. #define SetPageReserved(page) set_bit(PG_reserved, &((page)->flags)) #define ClearPageReserved(page) clear_bit(PG_reserved, &((page)->flags)) diff --git a/code/lab3/kern/mm/memlayout.h b/code/lab3/kern/mm/memlayout.h index f0c6816..33b4ea4 100644 --- a/code/lab3/kern/mm/memlayout.h +++ b/code/lab3/kern/mm/memlayout.h @@ -107,8 +107,8 @@ struct Page { }; /* Flags describing the status of a page frame */ -#define PG_reserved 0 // the page descriptor is reserved for kernel or unusable -#define PG_property 1 // the member 'property' is valid +#define PG_reserved 0 // if this bit=1: the Page is reserved for kernel, cannot be used in alloc/free_pages; otherwise, this bit=0 +#define PG_property 1 // if this bit=1: the Page is the head page of a free memory block(contains some continuous_addrress pages), and can be used in alloc_pages; if this bit=0: if the Page is the the head page of a free memory block, then this Page and the memory block is alloced. Or this Page isn't the head page. #define SetPageReserved(page) set_bit(PG_reserved, &((page)->flags)) #define ClearPageReserved(page) clear_bit(PG_reserved, &((page)->flags)) diff --git a/code/lab4/kern/mm/memlayout.h b/code/lab4/kern/mm/memlayout.h index b6b4094..af1fcb9 100644 --- a/code/lab4/kern/mm/memlayout.h +++ b/code/lab4/kern/mm/memlayout.h @@ -100,16 +100,15 @@ struct e820map { struct Page { int ref; // page frame's reference counter uint32_t flags; // array of flags that describe the status of the page frame - unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block - int zone_num; // used in buddy system, the No. of zone which the page belongs to + unsigned int property; // the num of free block, used in first fit pm manager list_entry_t page_link; // free list link list_entry_t pra_page_link; // used for pra (page replace algorithm) uintptr_t pra_vaddr; // used for pra (page replace algorithm) }; /* Flags describing the status of a page frame */ -#define PG_reserved 0 // the page descriptor is reserved for kernel or unusable -#define PG_property 1 // the member 'property' is valid +#define PG_reserved 0 // if this bit=1: the Page is reserved for kernel, cannot be used in alloc/free_pages; otherwise, this bit=0 +#define PG_property 1 // if this bit=1: the Page is the head page of a free memory block(contains some continuous_addrress pages), and can be used in alloc_pages; if this bit=0: if the Page is the the head page of a free memory block, then this Page and the memory block is alloced. Or this Page isn't the head page. #define SetPageReserved(page) set_bit(PG_reserved, &((page)->flags)) #define ClearPageReserved(page) clear_bit(PG_reserved, &((page)->flags)) diff --git a/code/lab5/kern/mm/memlayout.h b/code/lab5/kern/mm/memlayout.h index 825dd66..aa6a4ce 100644 --- a/code/lab5/kern/mm/memlayout.h +++ b/code/lab5/kern/mm/memlayout.h @@ -129,16 +129,15 @@ struct e820map { struct Page { int ref; // page frame's reference counter uint32_t flags; // array of flags that describe the status of the page frame - unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block - int zone_num; // used in buddy system, the No. of zone which the page belongs to + unsigned int property; // the num of free block, used in first fit pm manager list_entry_t page_link; // free list link list_entry_t pra_page_link; // used for pra (page replace algorithm) uintptr_t pra_vaddr; // used for pra (page replace algorithm) }; /* Flags describing the status of a page frame */ -#define PG_reserved 0 // the page descriptor is reserved for kernel or unusable -#define PG_property 1 // the member 'property' is valid +#define PG_reserved 0 // if this bit=1: the Page is reserved for kernel, cannot be used in alloc/free_pages; otherwise, this bit=0 +#define PG_property 1 // if this bit=1: the Page is the head page of a free memory block(contains some continuous_addrress pages), and can be used in alloc_pages; if this bit=0: if the Page is the the head page of a free memory block, then this Page and the memory block is alloced. Or this Page isn't the head page. #define SetPageReserved(page) set_bit(PG_reserved, &((page)->flags)) #define ClearPageReserved(page) clear_bit(PG_reserved, &((page)->flags)) diff --git a/code/lab6/kern/mm/memlayout.h b/code/lab6/kern/mm/memlayout.h index 825dd66..aa6a4ce 100644 --- a/code/lab6/kern/mm/memlayout.h +++ b/code/lab6/kern/mm/memlayout.h @@ -129,16 +129,15 @@ struct e820map { struct Page { int ref; // page frame's reference counter uint32_t flags; // array of flags that describe the status of the page frame - unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block - int zone_num; // used in buddy system, the No. of zone which the page belongs to + unsigned int property; // the num of free block, used in first fit pm manager list_entry_t page_link; // free list link list_entry_t pra_page_link; // used for pra (page replace algorithm) uintptr_t pra_vaddr; // used for pra (page replace algorithm) }; /* Flags describing the status of a page frame */ -#define PG_reserved 0 // the page descriptor is reserved for kernel or unusable -#define PG_property 1 // the member 'property' is valid +#define PG_reserved 0 // if this bit=1: the Page is reserved for kernel, cannot be used in alloc/free_pages; otherwise, this bit=0 +#define PG_property 1 // if this bit=1: the Page is the head page of a free memory block(contains some continuous_addrress pages), and can be used in alloc_pages; if this bit=0: if the Page is the the head page of a free memory block, then this Page and the memory block is alloced. Or this Page isn't the head page. #define SetPageReserved(page) set_bit(PG_reserved, &((page)->flags)) #define ClearPageReserved(page) clear_bit(PG_reserved, &((page)->flags)) diff --git a/code/lab7/kern/mm/memlayout.h b/code/lab7/kern/mm/memlayout.h index 825dd66..aa6a4ce 100644 --- a/code/lab7/kern/mm/memlayout.h +++ b/code/lab7/kern/mm/memlayout.h @@ -129,16 +129,15 @@ struct e820map { struct Page { int ref; // page frame's reference counter uint32_t flags; // array of flags that describe the status of the page frame - unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block - int zone_num; // used in buddy system, the No. of zone which the page belongs to + unsigned int property; // the num of free block, used in first fit pm manager list_entry_t page_link; // free list link list_entry_t pra_page_link; // used for pra (page replace algorithm) uintptr_t pra_vaddr; // used for pra (page replace algorithm) }; /* Flags describing the status of a page frame */ -#define PG_reserved 0 // the page descriptor is reserved for kernel or unusable -#define PG_property 1 // the member 'property' is valid +#define PG_reserved 0 // if this bit=1: the Page is reserved for kernel, cannot be used in alloc/free_pages; otherwise, this bit=0 +#define PG_property 1 // if this bit=1: the Page is the head page of a free memory block(contains some continuous_addrress pages), and can be used in alloc_pages; if this bit=0: if the Page is the the head page of a free memory block, then this Page and the memory block is alloced. Or this Page isn't the head page. #define SetPageReserved(page) set_bit(PG_reserved, &((page)->flags)) #define ClearPageReserved(page) clear_bit(PG_reserved, &((page)->flags)) diff --git a/code/lab8/kern/mm/memlayout.h b/code/lab8/kern/mm/memlayout.h index 825dd66..aa6a4ce 100644 --- a/code/lab8/kern/mm/memlayout.h +++ b/code/lab8/kern/mm/memlayout.h @@ -129,16 +129,15 @@ struct e820map { struct Page { int ref; // page frame's reference counter uint32_t flags; // array of flags that describe the status of the page frame - unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block - int zone_num; // used in buddy system, the No. of zone which the page belongs to + unsigned int property; // the num of free block, used in first fit pm manager list_entry_t page_link; // free list link list_entry_t pra_page_link; // used for pra (page replace algorithm) uintptr_t pra_vaddr; // used for pra (page replace algorithm) }; /* Flags describing the status of a page frame */ -#define PG_reserved 0 // the page descriptor is reserved for kernel or unusable -#define PG_property 1 // the member 'property' is valid +#define PG_reserved 0 // if this bit=1: the Page is reserved for kernel, cannot be used in alloc/free_pages; otherwise, this bit=0 +#define PG_property 1 // if this bit=1: the Page is the head page of a free memory block(contains some continuous_addrress pages), and can be used in alloc_pages; if this bit=0: if the Page is the the head page of a free memory block, then this Page and the memory block is alloced. Or this Page isn't the head page. #define SetPageReserved(page) set_bit(PG_reserved, &((page)->flags)) #define ClearPageReserved(page) clear_bit(PG_reserved, &((page)->flags))