Premier push en tant que BUT2

This commit is contained in:
Arnaud NGWALA NGWALA 2023-09-07 16:18:06 +02:00
parent 0241729e67
commit ca00974969
33 changed files with 2011 additions and 0 deletions

View File

@ -0,0 +1,23 @@
Question 1)
/etc/resolv.conf
Question 2)
eru.arda.lan
II/Question 1)
tshark -i eno1 -V -f "host 172.16.3.219 and not arp"
Question 2)
dig iluvatar.arda.lan
Question 3)
L'adresse IPv4
Question 4)
qr aa rd ra
Question 5)
aa
Question 6)
3600s, le temps de validité

1
SCR2.1/TP16/raspberry-ip Normal file
View File

@ -0,0 +1 @@
172.16.3.176

View File

@ -0,0 +1,6 @@
Question 1)
Le système d'exploitation est 64-bits
Question 2)
L'architecture est aarch64
Le processeur est un ARM Cortex-A53

113
SCR2.2/TP20/simple1.imn Normal file
View File

@ -0,0 +1,113 @@
node n0 {
type lanswitch
network-config {
hostname switch1
!
}
canvas c0
iconcoords {408 144}
labelcoords {408 167}
interface-peer {e0 n1}
interface-peer {e1 n2}
interface-peer {e2 n3}
}
node n1 {
type pc
network-config {
hostname pc1
!
interface eth0
ipv6 address fc00::20/64
mac address 42:00:aa:00:00:00
ip address 172.16.1.1/16
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {192 288}
labelcoords {192 319}
interface-peer {eth0 n0}
}
node n2 {
type pc
network-config {
hostname pc2
!
interface eth0
ipv6 address fc00::21/64
mac address 42:00:aa:00:00:01
ip address 172.16.2.2/16
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {408 312}
labelcoords {408 343}
interface-peer {eth0 n0}
}
node n3 {
type pc
network-config {
hostname pc3
!
interface eth0
ipv6 address fc00::22/64
mac address 42:00:aa:00:00:02
ip address 172.16.3.3/16
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {648 264}
labelcoords {648 295}
interface-peer {eth0 n0}
}
link l0 {
nodes {n0 n1}
bandwidth 0
}
link l1 {
nodes {n2 n0}
bandwidth 0
}
link l2 {
nodes {n3 n0}
bandwidth 0
}
canvas c0 {
name {Canvas0}
}
option show {
interface_names yes
ip_addresses yes
ipv6_addresses no
node_labels yes
link_labels yes
background_images no
annotations yes
hostsAutoAssign no
grid yes
iconSize normal
zoom 1.0
}

200
SCR2.2/TP20/simple2.imn Normal file
View File

@ -0,0 +1,200 @@
node n0 {
type host
network-config {
hostname host1
!
interface eth1
ipv6 address fc00:1::10/64
mac address 42:00:aa:00:00:01
ip address 172.16.2.254/24
!
interface eth0
ipv6 address fc00::10/64
mac address 42:00:aa:00:00:00
ip address 172.16.1.254/24
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {432 120}
labelcoords {432 156}
interface-peer {eth0 n1}
interface-peer {eth1 n2}
}
node n1 {
type lanswitch
network-config {
hostname switch1
!
}
canvas c0
iconcoords {192 192}
labelcoords {192 215}
interface-peer {e0 n0}
interface-peer {e1 n3}
interface-peer {e2 n4}
}
node n2 {
type lanswitch
network-config {
hostname switch2
!
}
canvas c0
iconcoords {648 192}
labelcoords {648 215}
interface-peer {e0 n0}
interface-peer {e1 n5}
interface-peer {e2 n6}
}
node n3 {
type pc
network-config {
hostname pc1-1
!
interface eth0
ipv6 address fc00::20/64
mac address 42:00:aa:00:00:02
ip address 172.16.1.1/24
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 172.16.2.0/24 172.16.1.254
!
}
canvas c0
iconcoords {72 384}
labelcoords {72 415}
interface-peer {eth0 n1}
}
node n4 {
type pc
network-config {
hostname pc1-2
!
interface eth0
ipv6 address fc00::21/64
mac address 42:00:aa:00:00:03
ip address 172.16.1.2/24
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 172.16.2.0/24 172.16.1.254
!
}
canvas c0
iconcoords {288 384}
labelcoords {288 415}
interface-peer {eth0 n1}
}
node n5 {
type pc
network-config {
hostname pc2-1
!
interface eth0
ipv6 address fc00:1::20/64
mac address 42:00:aa:00:00:04
ip address 172.16.2.1/24
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 172.16.1.0/24 172.16.2.254
!
}
canvas c0
iconcoords {576 384}
labelcoords {576 415}
interface-peer {eth0 n2}
}
node n6 {
type pc
network-config {
hostname p2-2
!
interface eth0
ipv6 address fc00:1::21/64
mac address 42:00:aa:00:00:05
ip address 172.16.2.2/24
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 172.16.1.0/24 172.16.2.254
!
}
canvas c0
iconcoords {768 384}
labelcoords {768 415}
interface-peer {eth0 n2}
}
link l0 {
nodes {n0 n1}
bandwidth 0
}
link l1 {
nodes {n2 n0}
bandwidth 0
}
link l2 {
nodes {n1 n3}
bandwidth 0
}
link l3 {
nodes {n4 n1}
bandwidth 0
}
link l4 {
nodes {n5 n2}
bandwidth 0
}
link l5 {
nodes {n6 n2}
bandwidth 0
}
canvas c0 {
name {Canvas0}
}
option show {
interface_names yes
ip_addresses yes
ipv6_addresses no
node_labels yes
link_labels yes
background_images no
annotations yes
hostsAutoAssign no
grid yes
iconSize normal
zoom 1.0
}

415
SCR2.2/TP20/simple3.imn Normal file
View File

@ -0,0 +1,415 @@
node n0 {
type host
network-config {
hostname P1
!
interface eth1
ipv6 address fc00:1::10/64
mac address 42:00:aa:00:00:01
ip address 192.168.127.253/18
!
interface eth0
ipv6 address fc00::10/64
mac address 42:00:aa:00:00:00
ip address 192.168.63.254/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.128.0/18 192.168.127.254
ip route 192.168.192.0/18 192.168.127.254
!
}
canvas c0
iconcoords {216 72}
labelcoords {216 108}
interface-peer {eth0 n1}
interface-peer {eth1 n2}
}
node n1 {
type lanswitch
network-config {
hostname S1
!
}
canvas c0
iconcoords {120 168}
labelcoords {120 191}
interface-peer {e0 n0}
interface-peer {e1 n5}
interface-peer {e2 n6}
}
node n2 {
type lanswitch
network-config {
hostname S2
!
}
canvas c0
iconcoords {288 168}
labelcoords {288 191}
interface-peer {e0 n0}
interface-peer {e1 n3}
interface-peer {e2 n7}
interface-peer {e3 n8}
}
node n3 {
type host
network-config {
hostname P2
!
interface eth2
ipv6 address fc00:3::10/64
mac address 42:00:aa:00:00:0a
ip address 192.168.191.254/18
!
interface eth1
ipv6 address fc00:2::10/64
mac address 42:00:aa:00:00:03
ip address 192.168.255.254/18
!
interface eth0
ipv6 address fc00:1::11/64
mac address 42:00:aa:00:00:02
ip address 192.168.127.254/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.0.0/18 192.168.127.253
!
}
canvas c0
iconcoords {528 72}
labelcoords {528 108}
interface-peer {eth0 n2}
interface-peer {eth1 n4}
interface-peer {eth2 n11}
}
node n4 {
type lanswitch
network-config {
hostname S4
!
}
canvas c0
iconcoords {720 168}
labelcoords {720 191}
interface-peer {e0 n3}
interface-peer {e1 n9}
interface-peer {e2 n10}
}
node n5 {
type pc
network-config {
hostname pc1-1
!
interface eth0
ipv6 address fc00::20/64
mac address 42:00:aa:00:00:04
ip address 192.168.6.23/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.128.0/18 192.168.63.254
ip route 192.168.192.0/18 192.168.63.254
ip route 192.168.64.0/18 192.168.63.254
!
}
canvas c0
iconcoords {24 288}
labelcoords {24 319}
interface-peer {eth0 n1}
}
node n6 {
type pc
network-config {
hostname pc1-2
!
interface eth0
ipv6 address fc00::21/64
mac address 42:00:aa:00:00:05
ip address 192.168.17.23/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.128.0/18 192.168.63.254
ip route 192.168.192.0/18 192.168.63.254
ip route 192.168.64.0/18 192.168.63.254
!
}
canvas c0
iconcoords {216 264}
labelcoords {216 295}
interface-peer {eth0 n1}
}
node n7 {
type pc
network-config {
hostname pc2-1
!
interface eth0
ipv6 address fc00:1::20/64
mac address 42:00:aa:00:00:06
ip address 192.168.68.12/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.0.0/18 192.168.127.253
ip route 192.168.128.0/18 192.168.127.254
ip route 192.168.192.0/18 192.168.127.254
!
}
canvas c0
iconcoords {192 408}
labelcoords {192 439}
interface-peer {eth0 n2}
}
node n8 {
type pc
network-config {
hostname pc2-2
!
interface eth0
ipv6 address fc00:1::21/64
mac address 42:00:aa:00:00:07
ip address 192.168.66.14/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.0.0/18 192.168.127.253
ip route 192.168.128.0/18 192.168.127.254
ip route 192.168.192.0/18 192.168.127.254
!
}
canvas c0
iconcoords {384 408}
labelcoords {384 439}
interface-peer {eth0 n2}
}
node n9 {
type pc
network-config {
hostname pc4-1
!
interface eth0
ipv6 address fc00:2::20/64
mac address 42:00:aa:00:00:08
ip address 192.168.200.27/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.0.0/18 192.168.255.254
ip route 192.168.192.0/18 192.168.255.254
ip route 192.168.64.0/18 192.168.255.254
!
}
canvas c0
iconcoords {600 360}
labelcoords {600 391}
interface-peer {eth0 n4}
}
node n10 {
type pc
network-config {
hostname pc4-2
!
interface eth0
ipv6 address fc00:2::21/64
mac address 42:00:aa:00:00:09
ip address 192.168.216.80/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.0.0/18 192.168.255.254
ip route 192.168.192.0/18 192.168.255.254
ip route 192.168.64.0/18 192.168.255.254
!
}
canvas c0
iconcoords {864 360}
labelcoords {864 391}
interface-peer {eth0 n4}
}
node n11 {
type lanswitch
network-config {
hostname S3
!
}
canvas c0
iconcoords {504 216}
labelcoords {504 239}
interface-peer {e0 n3}
interface-peer {e1 n12}
interface-peer {e2 n13}
}
node n12 {
type pc
network-config {
hostname pc3-1
!
interface eth0
ipv6 address fc00:3::20/64
mac address 42:00:aa:00:00:0b
ip address 192.168.131.16/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.0.0/18 192.168.191.254
ip route 192.168.192.0/18 192.168.191.254
ip route 192.168.64.0/18 192.168.191.254
!
}
canvas c0
iconcoords {408 504}
labelcoords {408 535}
interface-peer {eth0 n11}
}
node n13 {
type pc
network-config {
hostname pc3-2
!
interface eth0
ipv6 address fc00:3::21/64
mac address 42:00:aa:00:00:0c
ip address 192.168.164.237/18
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
ip route 192.168.0.0/18 192.168.191.254
ip route 192.168.192.0/18 192.168.191.254
ip route 192.168.64.0/18 192.168.191.254
!
}
canvas c0
iconcoords {624 504}
labelcoords {624 535}
interface-peer {eth0 n11}
}
link l0 {
nodes {n1 n0}
bandwidth 0
}
link l1 {
nodes {n2 n0}
bandwidth 0
}
link l2 {
nodes {n3 n2}
bandwidth 0
}
link l3 {
nodes {n4 n3}
bandwidth 0
}
link l4 {
nodes {n5 n1}
bandwidth 0
}
link l5 {
nodes {n6 n1}
bandwidth 0
}
link l6 {
nodes {n7 n2}
bandwidth 0
}
link l7 {
nodes {n8 n2}
bandwidth 0
}
link l8 {
nodes {n9 n4}
bandwidth 0
}
link l9 {
nodes {n10 n4}
bandwidth 0
}
link l10 {
nodes {n11 n3}
bandwidth 0
}
link l11 {
nodes {n12 n11}
bandwidth 0
}
link l12 {
nodes {n13 n11}
bandwidth 0
}
canvas c0 {
name {Canvas0}
}
option show {
interface_names yes
ip_addresses yes
ipv6_addresses no
node_labels yes
link_labels yes
background_images no
annotations yes
hostsAutoAssign no
grid yes
iconSize normal
zoom 1.0
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,29 @@
/* adresses virtuelles d'un processus */
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
int t[1000] = {[0 ... 999] = 2};
int main(int argc, char * argv[])
{
int i=3;
static int j = 3;
char * m = (char*)malloc(1);
printf("mon pid est %d\n\n",getpid());
/* ------- Affichage des adresses --------*/
printf("main\t=\t%p\n",main);
printf("&argc\t=\t%p\n",&argc);
printf("&i\t=\t%p\n",&i);
printf("&j\t=\t%p\n",&j);
printf("t\t=\t%p\n",t);
printf("m\t=\t%p\n",m);
getchar();
}

View File

@ -0,0 +1,55 @@
/* alignement et objets */
struct exemple1 {
int x;
int y;
int z;
int w;
};
struct exemple2 {
char x;
char y;
char z;
char w;
};
struct exemple3 {
int x;
int y;
char z;
char w;
};
struct exemple4 {
int x;
char y;
int z;
char w;
};
union exemple5 {
int x;
char y;
int z;
char w;
};
int main()
{
int a[4] = {1,2,3,4};
char c[4] = {'a','b','c','d'};
struct exemple1 ex1 = {1,2,3,4};
struct exemple2 ex2 = {'a','b','c','d'};
struct exemple3 ex3 = {1,2,'c','d'};
struct exemple4 ex4 = {1,'c',2,'d'};
union exemple5 ex5;
int x = 61;
char y = 62;
int z = 63;
char w = 64;
ex5.x=62;ex5.y=63;ex5.z=64;ex5.w=65;
// appelez hexdump pour chaque variable
}

10
SCR3.1/TP1/src/bss_data.c Normal file
View File

@ -0,0 +1,10 @@
/* segment bss et data */
#define N 1000
int t[N]; /* version 1 */
//int t[N]={1}; /* version 2 */
int main()
{
return 0;
}

View File

@ -0,0 +1,17 @@
CFLAGS := -Wall -g -O0
SRC=buf.c heap.c huge.c mmap.c null.c stack.c
DEPENDHELPERS=helpers.o
BINARIES=$(SRC:%.c=%)
%.o : %c
gcc -c $+
$(BINARIES): % : %.o $(DEPENDHELPERS)
gcc -o $@ $+
all : $(BINARIES)
clean:
rm -f *.o $(BINARIES)

BIN
SCR3.1/TP1/src/ex1bis/buf Executable file

Binary file not shown.

View File

@ -0,0 +1,10 @@
#include "helpers.h"
static char buf1[8 MB] = {0};
static char buf2[16 MB] = {0};
int main(int argc, char **argv)
{
randomize(buf2, 16 MB);
return interlude();
}

Binary file not shown.

BIN
SCR3.1/TP1/src/ex1bis/heap Executable file

Binary file not shown.

View File

@ -0,0 +1,8 @@
#include "helpers.h"
int main(int argc, char **argv)
{
dirty(16 MB);
clean(32 MB);
return interlude();
}

View File

@ -0,0 +1,36 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "helpers.h"
#include <stdlib.h>
void randomize(char *buf, size_t n)
{
assert(buf);
memset(buf, rand() & 0xff, n);
}
void clean(size_t b)
{
for (; b > 0; b -= 1 KB)
calloc(1 KB, sizeof(char));
}
void dirty(size_t b)
{
for (; b > 0; b -= 1 KB)
randomize(calloc(1 KB, sizeof(char)), 1 KB);
}
int interlude(void)
{
pid_t pid = getpid();
printf("pid %i\n", (int)pid);
printf("------------------------------------------\n"
"go check /proc/%i/smaps; I'll wait...\n"
"press <Enter> when you're done\n", pid);
fgetc(stdin);
return 0;
}

View File

@ -0,0 +1,13 @@
#ifndef _HELPERS_H
#define _HELPERS_H
#include <stdlib.h>
#define KB * 1024
#define MB * 1024 * 1024
void randomize(char *buf, size_t n);
void clean(size_t n);
void dirty(size_t n);
int interlude(void);
#endif

BIN
SCR3.1/TP1/src/ex1bis/huge Executable file

Binary file not shown.

View File

@ -0,0 +1,12 @@
#include "helpers.h"
int main(int argc, char **argv)
{
char *under = malloc(96 KB);
randomize(under, 96 KB);
char *over = malloc(256 KB);
randomize(over, 256 KB);
return interlude();
}

BIN
SCR3.1/TP1/src/ex1bis/mmap Executable file

Binary file not shown.

View File

@ -0,0 +1,38 @@
#include "helpers.h"
#include <sys/mman.h>
#include <assert.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
/* inert map (never modified) */
char *inert = mmap(NULL, 16 KB,
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
/* anonymous, private mmap */
char *anon_priv = mmap(NULL, 32 KB,
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
randomize(anon_priv, 32 KB);
/* anonymous, shared map */
char *anon_shared = mmap(NULL, 64 KB,
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_SHARED,
-1, 0);
randomize(anon_shared, 64 KB);
/* private, file-backed map */
int fd = open("data/256k", O_RDWR);
assert(fd >= 0);
char *file = mmap(NULL, 256 KB,
PROT_READ|PROT_WRITE,
MAP_PRIVATE,
fd, 0);
randomize(file, 128 KB);
return interlude();
}

BIN
SCR3.1/TP1/src/ex1bis/null Executable file

Binary file not shown.

View File

@ -0,0 +1,6 @@
#include "helpers.h"
int main(int argc, char **argv)
{
return interlude();
}

BIN
SCR3.1/TP1/src/ex1bis/stack Executable file

Binary file not shown.

View File

@ -0,0 +1,8 @@
#include "helpers.h"
int main (int argc, char **argv)
{
char buf[28 KB] = {0};
randomize(buf, 28 KB);
return interlude();
}

38
SCR3.1/TP1/src/ij_ji.c Normal file
View File

@ -0,0 +1,38 @@
/* accès mémoire */
#include<stdio.h>
#include<time.h>
#include <stdlib.h>
#define N 8192
int t[N][N];
static inline double tstamp(void)
{
struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv);
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
}
int main()
{
int i,j;
double t1,t2;
t1=tstamp();
/* version 1 */
for(i=0;i<N;i++) for(j=0;j<N;j++)
t[i][j] = 1;
/* version 2 */
// for(i=0;i<N;i++) for(j=0;j<N;j++)
//t[j][i] = 1;
//
t2=tstamp();
printf("time = %lf\n",t2-t1);
return 0;
}

View File

@ -0,0 +1,5 @@
mem.o : mem.h mem.c
gcc -c mem.c
main : main.c mem.o
gcc -o main main.c mem.o

View File

@ -0,0 +1,9 @@
#include<stdio.h>
#include "mem.h"
int main(int argc,char * argv[])
{
int pages[] = {4,5,6,8,4,9,6,12,4,6,10};
simu(4,pages,11);
}

View File

@ -0,0 +1,174 @@
#include "mem.h"
#include <stdlib.h>
#include<stdio.h>
#include<string.h>
typedef struct frame {
int no;
int page;
int r; /* bit pour la seconde chance */
} frame ;
typedef struct fifo {
int head;
int tail;
int nbelem;
} fifo;
typedef struct mem {
int nbframes;
frame * frames;
} mem;
static mem * memory=NULL;
static fifo FIFO;
/* Fifo est buffer circulaire
* head pointe sur la tete (element le plus ancien)
* tail pointe sur la queue (element le plus recent)
* nbelem represente le nombre d'element dans la file
* head et tail progressent modulo le nombre de frame
* dans la memoire */
/*
* Memoire
-------------
| frame 0 | <- head
-------------
| frame 1 |
-------------
| frame 2 |
-------------
| frame 3 |
-------------
| frame 4 |
-------------
| ... |
-------------
| ... |
-------------
| ... | <- tail
-------------
| ... |
-------------
*/
static int init(int n)
{
int i;
memory = (mem*)calloc(1,sizeof(mem));
memory-> nbframes = n;
memory-> frames = (frame *) calloc(n,sizeof(frame));
if (memory -> frames == NULL) return -1;
for(i=0;i<n;i++){
memory->frames[i].no = i;
memory->frames[i].page = -1; /* les frames sont vides initialement */
memory->frames[i].r=0;
}
FIFO.head = FIFO.tail = 0;
FIFO.nbelem = 0;
return n;
}
static int _page_is_in(int page)
{
/* a ecrire */
}
static int _fifo_is_full()
{
return (FIFO.nbelem == memory->nbframes);
}
int get_page_2chance(int page)
{
/* pour la deuxieme question */
}
int get_page_fifo(int page)
{
/* a ecrire */
}
void simu(int nb_frame,int t[],int l)
{
int i,j;
init(nb_frame);
frame ** trace;
trace = (frame **) malloc(sizeof(frame *) * l);
int * defaut = (int *) calloc(l,sizeof(int));
for (i=0;i<l+1;i++) trace[i] = (frame *) malloc(nb_frame * sizeof(frame));
for(i=0;i<l;i++){
defaut[i] = get_page_fifo(t[i]);
//defaut[i] = get_page_2chance(t[i]);
memcpy (trace[i],memory->frames,sizeof(frame)*nb_frame);
}
printf("------------");
for (i=0;i<l;i++){
printf("------",i+1);
}
printf("\n");
printf("|temps | ");
for (i=0;i<l;i++){
printf(" %3d |",i);
}
printf("\n");
printf("------------");
for (i=0;i<l;i++){
printf("------",i+1);
}
printf("\n");
printf("|page | ");
for (i=0;i<l;i++){
printf(" %3d |",t[i]);
}
printf("\n");
printf("------------");
for (i=0;i<l;i++){
printf("------",i+1);
}
printf("\n");
for(j=0;j<nb_frame;j++){
printf("|frame %3d| ",j);
for(i=0;i<l;i++){
if (trace[i][j].page !=-1) printf(" %3d |",trace[i][j].page);
else printf(" X |");
}
printf("\n");
printf("------------");
for (i=0;i<l;i++){
printf("------",i+1);
}
printf("\n");
}
printf("|default | ");
for (i=0;i<l;i++){
printf(" %3d |",!defaut[i]);
}
printf("\n");
printf("------------");
for (i=0;i<l;i++){
printf("------",i+1);
}
printf("\n");
free(memory->frames);
free(memory);
memory = NULL;
for(i=0;i<l;i++) free(trace[i]);
free(trace);
}

View File

@ -0,0 +1,8 @@
#ifndef _MEM_H
#define _MEM_H
void simu(
int nb_frame, /* nombre de cadre */
int t[], /* pages de la simulation */
int l); /* nombres de pages pour la simulation */
#endif

108
SCR3.1/TP1/src/sum_array.c Normal file
View File

@ -0,0 +1,108 @@
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
static inline double tstamp(void)
{
struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv);
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
}
void shuffle(int *array, size_t n)
{
if (n > 1)
{
size_t i;
for (i = 0; i < n - 1; i++)
// for (i = 0; i < n ; i++)
{
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
// size_t j = rand()%n;
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
}
void init_access_c(int access[],size_t size)
{
int i;
for(i=0;i<size;i++) access[i] = i;
}
void init_access_d(int access[],size_t size)
{
int i;
for(i=0;i<size;i++) access[i] = size-i-1;
}
void init_access_a(int access[],size_t size)
{
init_access_c(access,size);
shuffle(access,size);
}
void init_array(int t[],int N)
{
int i;
for(i=0;i<N;i++) t[i] = i ;
}
long int sum_array(int t[],int access[],size_t size)
{
long int S=0;
int i;
for(i=0;i<size;i++) S += t[access[i]];
return S;
}
int main(int argc,char * argv[])
{
double t1,t2;
int * array; // tableau à sommer (contient les tous les entiers [0,SIZE-1]
int * access;
int i,size;
long int S=0;
if (argc !=3) {
printf("%s -c|-d|-a SIZE\n",argv[0]);
return 1;
}
size=strtol(argv[2],NULL,0);
array=(int *)malloc(sizeof(int)*size);
assert(array != NULL);
access=(int *)malloc(sizeof(int)*size);
assert(access != NULL);
init_array(array,size);
if (strcmp(argv[1],"-c") == 0)
init_access_c(access,size);
if (strcmp(argv[1],"-d") == 0)
init_access_d(access,size);
if (strcmp(argv[1],"-a") == 0)
init_access_a(access,size);
/* On somme les elements en accedant au tableau
* sequentiellement (croissant/décroissant), ou
* de manière aléatoire
* */
t1=tstamp();
S= sum_array(array,access,size);
t2=tstamp();
printf("S=%ld %lf\n",S,(t2-t1));
}