PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Functions | Variables
parallel-merge.c File Reference
#include "tests/vm/parallel-merge.h"
#include <stdio.h>
#include <syscall.h>
#include "tests/arc4.h"
#include "tests/lib.h"
#include "tests/main.h"
Include dependency graph for parallel-merge.c:

Go to the source code of this file.

Macros

#define CHUNK_SIZE   (128 * 1024)
 Generates about 1 MB of random data that is then divided into 16 chunks. More...
 
#define CHUNK_CNT   8
 Number of chunks. More...
 
#define DATA_SIZE   (CHUNK_CNT * CHUNK_SIZE)
 Buffer size. More...
 

Functions

static void init (void)
 Initialize buf1 with random data, then count the number of instances of each value within it. More...
 
static void sort_chunks (const char *subprocess, int exit_status)
 Sort each chunk of buf1 using SUBPROCESS, which is expected to return EXIT_STATUS. More...
 
static void merge (void)
 Merge the sorted chunks in buf1 into a fully sorted buf2. More...
 
static void verify (void)
 
void parallel_merge (const char *child_name, int exit_status)
 tests/vm/parallel-merge.h More...
 

Variables

unsigned char buf1 [DATA_SIZE]
 
unsigned char buf2 [DATA_SIZE]
 
size_t histogram [256]
 

Macro Definition Documentation

◆ CHUNK_CNT

#define CHUNK_CNT   8

Number of chunks.

Definition at line 14 of file parallel-merge.c.

◆ CHUNK_SIZE

#define CHUNK_SIZE   (128 * 1024)

Generates about 1 MB of random data that is then divided into 16 chunks.

A separate subprocess sorts each chunk; the subprocesses run in parallel. Then we merge the chunks and verify that the result is what it should be.

Definition at line 13 of file parallel-merge.c.

◆ DATA_SIZE

#define DATA_SIZE   (CHUNK_CNT * CHUNK_SIZE)

Buffer size.

Definition at line 15 of file parallel-merge.c.

Function Documentation

◆ init()

static void init ( void  )
static

Initialize buf1 with random data, then count the number of instances of each value within it.

Definition at line 23 of file parallel-merge.c.

References arc4_crypt(), arc4_init(), buf1, histogram, arc4::i, and msg().

Referenced by parallel_merge().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ merge()

static void merge ( void  )
static

Merge the sorted chunks in buf1 into a fully sorted buf2.

Definition at line 85 of file parallel-merge.c.

References buf1, buf2, CHUNK_CNT, CHUNK_SIZE, arc4::i, and msg().

Referenced by parallel_merge().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parallel_merge()

void parallel_merge ( const char *  child_name,
int  exit_status 
)

tests/vm/parallel-merge.h

Definition at line 143 of file parallel-merge.c.

References init(), merge(), sort_chunks(), and verify().

Referenced by test_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sort_chunks()

static void sort_chunks ( const char *  subprocess,
int  exit_status 
)
static

Sort each chunk of buf1 using SUBPROCESS, which is expected to return EXIT_STATUS.

Definition at line 39 of file parallel-merge.c.

References buf1, CHECK, CHUNK_CNT, CHUNK_SIZE, close(), create(), exec(), arc4::i, msg(), open(), quiet, read(), snprintf(), wait(), and write().

Referenced by parallel_merge().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify()

static void verify ( void  )
static

Definition at line 120 of file parallel-merge.c.

References buf2, fail(), histogram, and msg().

Referenced by parallel_merge().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ buf1

unsigned char buf1[DATA_SIZE]

Definition at line 17 of file parallel-merge.c.

Referenced by init(), merge(), and sort_chunks().

◆ buf2

unsigned char buf2[DATA_SIZE]

Definition at line 17 of file parallel-merge.c.

Referenced by merge(), and verify().

◆ histogram

size_t histogram[256]

Definition at line 18 of file parallel-merge.c.

Referenced by init(), and verify().