Merge branch 'gleb/BSD' into 'BSD-merged'
Merge rewritten inline funcs into main BSD repo See merge request lab2425_autumn/pintos_22!4
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -24,5 +24,6 @@
|
|||||||
*.nav
|
*.nav
|
||||||
*.toc
|
*.toc
|
||||||
|
|
||||||
#ignore files from CLion IDE
|
#ignore files from CLion/VSCode IDEs
|
||||||
.idea
|
.idea
|
||||||
|
.vscode
|
||||||
@@ -1,26 +1,95 @@
|
|||||||
|
#include <stdint.h>
|
||||||
#ifndef FIXED_POINT_H
|
#ifndef FIXED_POINT_H
|
||||||
#define FIXED_POINT_H
|
#define FIXED_POINT_H
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int32_t raw;
|
||||||
|
} fp32_t;
|
||||||
|
|
||||||
/* Fixed Point Arithmetic bit count constants */
|
/* Fixed Point Arithmetic bit count constants */
|
||||||
#define NUM_INT_BITS 11
|
|
||||||
#define NUM_FRAC_BITS 20
|
#define NUM_FRAC_BITS 20
|
||||||
|
#define NUM_INT_BITS (31 - NUM_FRAC_BITS)
|
||||||
#define CONVERSION_CONST (1 << NUM_FRAC_BITS) /* f = 2^q, (2^20) */
|
#define CONVERSION_CONST (1 << NUM_FRAC_BITS) /* f = 2^q, (2^20) */
|
||||||
|
|
||||||
/* Fixed Point Arithmetic conversion operations */
|
/* Fixed Point Arithmetic conversion operations */
|
||||||
#define INT_TO_FP(n) ((n) * (CONVERSION_CONST))
|
/* Converts an integer n to a fixed point number */
|
||||||
#define FLOOR_FP_TO_INT(x) ((x) / (CONVERSION_CONST))
|
inline fp32_t
|
||||||
#define ROUNDING_FP_TO_INT(x) ((x) >= 0 ? ((x) + ((CONVERSION_CONST) / 2)) : ((x) - ((CONVERSION_CONST) / 2))
|
int_to_fp (int32_t n)
|
||||||
|
{
|
||||||
|
return { n * CONVERSION_CONST };
|
||||||
|
}
|
||||||
|
|
||||||
/* Fixed Point Arithmetic addition operations */
|
/* Handles conversion of fixed point to integer. First version truncates, second one rounds */
|
||||||
#define FP_ADD(x, y) ((x) + (y))
|
inline int32_t
|
||||||
#define FP_SUBTRACT(x, y) ((x) - (y))
|
fp_floor (fp32_t x)
|
||||||
#define FP_ADD_INT(x, n) ((x) + ((n) * (CONVERSION_CONST)))
|
{
|
||||||
#define FP_SUBTRACT_INT(x, n) ((x) - ((n) * (CONVERSION_CONST)))
|
return { x.raw / CONVERSION_CONST };
|
||||||
|
}
|
||||||
|
|
||||||
/* Fixed Point Arithmetic multiplication operations */
|
inline int32_t
|
||||||
#define FP_MULTIPLY(x, y) ((int64_t)(x)) * (y) / (CONVERSION_CONST)
|
fp_round (fp32_t x)
|
||||||
#define FP_MULTIPLY_INT(x, n) ((x) * (n))
|
{
|
||||||
#define FP_DIVIDE(x, y) ((int64_t)(x)) * (CONVERSION_CONST) / (y)
|
if (x.raw >= 0)
|
||||||
#define FP_DIVIDE_INT(x, n) ((x) / (n))
|
return (x.raw + CONVERSION_CONST / 2) / CONVERSION_CONST;
|
||||||
|
else
|
||||||
|
return (x.raw - CONVERSION_CONST / 2) / CONVERSION_CONST;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add two fixed points */
|
||||||
|
inline fp32_t
|
||||||
|
fp_add (fp32_t x, fp32_t y)
|
||||||
|
{
|
||||||
|
return { x.raw + y.raw };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Subtract two fixed points */
|
||||||
|
inline fp32_t
|
||||||
|
fp_sub (fp32_t x, fp32_t y)
|
||||||
|
{
|
||||||
|
return { x.raw - y.raw };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add fixed point to integer */
|
||||||
|
inline fp32_t
|
||||||
|
fp_add_int (fp32_t x, int32_t n)
|
||||||
|
{
|
||||||
|
return { x.raw + n * CONVERSION_CONST };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Subtract integer from fixed point */
|
||||||
|
inline fp32_t
|
||||||
|
fp_sub_int (fp32_t x, int32_t n)
|
||||||
|
{
|
||||||
|
return { x.raw - n * CONVERSION_CONST };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Multiple two fixed points */
|
||||||
|
inline fp32_t
|
||||||
|
fp_mul (fp32_t x, fp32_t y)
|
||||||
|
{
|
||||||
|
return { ((int64_t)x.raw) * y.raw / CONVERSION_CONST };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Divide two fixed points */
|
||||||
|
inline fp32_t
|
||||||
|
fp_div (fp32_t x, fp32_t y)
|
||||||
|
{
|
||||||
|
return { ((int64_t)x.raw) * CONVERSION_CONST / y.raw };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Multiply fixed point and integer */
|
||||||
|
inline fp32_t
|
||||||
|
fp_mul_int (fp32_t x, int32_t n)
|
||||||
|
{
|
||||||
|
return { x.raw * n };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Divide fixed point by integer */
|
||||||
|
inline fp32_t
|
||||||
|
fp_div_int (fp32_t x, int32_t n)
|
||||||
|
{
|
||||||
|
return { x.raw / n };
|
||||||
|
}
|
||||||
|
|
||||||
#endif //FIXED_POINT_H
|
#endif //FIXED_POINT_H
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <random.h>
|
#include <random.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "threads/fixed-point.h"
|
||||||
#include "threads/flags.h"
|
#include "threads/flags.h"
|
||||||
#include "threads/interrupt.h"
|
#include "threads/interrupt.h"
|
||||||
#include "threads/intr-stubs.h"
|
#include "threads/intr-stubs.h"
|
||||||
@@ -375,8 +376,7 @@ thread_set_nice (int nice UNUSED)
|
|||||||
int
|
int
|
||||||
thread_get_nice (void)
|
thread_get_nice (void)
|
||||||
{
|
{
|
||||||
/* Not yet implemented. */
|
return thread_current ()->nice;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 100 times the system load average. */
|
/* Returns 100 times the system load average. */
|
||||||
@@ -391,8 +391,7 @@ thread_get_load_avg (void)
|
|||||||
int
|
int
|
||||||
thread_get_recent_cpu (void)
|
thread_get_recent_cpu (void)
|
||||||
{
|
{
|
||||||
/* Not yet implemented. */
|
return fp_round (fp_mul_int (thread_current ()->recent_cpu, 100));
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Idle thread. Executes when no other thread is ready to run.
|
/* Idle thread. Executes when no other thread is ready to run.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <list.h>
|
#include <list.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "threads/fixed-point.h"
|
||||||
|
|
||||||
/* States in a thread's life cycle. */
|
/* States in a thread's life cycle. */
|
||||||
enum thread_status
|
enum thread_status
|
||||||
@@ -93,6 +94,10 @@ struct thread
|
|||||||
/* Shared between thread.c and synch.c. */
|
/* Shared between thread.c and synch.c. */
|
||||||
struct list_elem elem; /* List element. */
|
struct list_elem elem; /* List element. */
|
||||||
|
|
||||||
|
/* MLFQS items */
|
||||||
|
int nice; /* Nice value for this thread */
|
||||||
|
fp32_t recent_cpu; /* Amount of time this process received */
|
||||||
|
|
||||||
#ifdef USERPROG
|
#ifdef USERPROG
|
||||||
/* Owned by userprog/process.c. */
|
/* Owned by userprog/process.c. */
|
||||||
uint32_t *pagedir; /* Page directory. */
|
uint32_t *pagedir; /* Page directory. */
|
||||||
|
|||||||
Reference in New Issue
Block a user