RinRi 1 anno fa
parent
commit
c0806e50e7
6 ha cambiato i file con 85 aggiunte e 0 eliminazioni
  1. +66
    -0
      week09/ex1.c
  2. BIN
      week09/ex1.out
  3. +9
    -0
      week09/ex1.sh
  4. +8
    -0
      week09/ex2.txt
  5. +1
    -0
      week09/input.txt
  6. +1
    -0
      week09/inputmy1.txt

+ 66
- 0
week09/ex1.c Vedi File

@@ -0,0 +1,66 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

typedef struct {
int page;
unsigned char count;
} PageFrame;

int findFrame(PageFrame *pframes, int n, int page) {
for (int i = 0; i < n; ++i)
if (pframes[i].page == page)
return i;

return -1;
}

int oldestFrame(PageFrame *pframes, int n) {
int mn = INT_MAX, mnpos = -1;
for (int i = 0; i < n; ++i)
if (pframes[i].page < mn)
mn = pframes[i].page, mnpos = i;

return mnpos;
}

/*
* My program doesn't simulate the "timer".
* Instead, it shifts everything every iteration.
* That's why I haven't implemented r-bits.
*/

int main(int argc, char **argv) {
FILE *f = fopen("input.txt", "r");

PageFrame pframes[100];
for (int i = 0; i < 100; ++i)
pframes[i].page = -1, pframes[i].count = 0;

int testFrames = atoi(argv[1]);

float miss = 0, hit = 0;
unsigned long page;

while (fscanf(f, "%lu", &page) != EOF) {
int frame = findFrame(pframes, testFrames, page);
if (frame == -1) {
miss++;
int oldest = oldestFrame(pframes, testFrames);
pframes[oldest].page = page;
pframes[oldest].count = (1 << 7);
} else {
hit++;
pframes[frame].count |= (1 << 7);
}

// do refresh after every access
for (int i = 0; i < testFrames; ++i)
pframes[i].count >>= 1;
}

printf ("hits: %f\nmisses: %f\nratio: %f\n", hit, miss, hit / miss);

fclose(f);
}

BIN
week09/ex1.out Vedi File


+ 9
- 0
week09/ex1.sh Vedi File

@@ -0,0 +1,9 @@
#!/bin/sh

gcc ex1.c -o ex1.out
echo "10"
./ex1.out 10
echo "50"
./ex1.out 50
echo "100"
./ex1.out 100

+ 8
- 0
week09/ex2.txt Vedi File

@@ -0,0 +1,8 @@
In case when most frequently and recently used pages repeat,
the number of hits increases, while misses decrease.

The test case in "inputmy1.txt" clearly demostrates the point
above, when there are few page frames available.

When pages appear more randomly compared to the previous case,
the number of misses increases.

+ 1
- 0
week09/input.txt Vedi File

@@ -0,0 +1 @@
337 490 194 973 151 425 722 816 331 760 864 53 416 170 829 434 181 731 86 544 29 559 629 411 365 368 802 962 529 833 8 435 564 94 64 695 654 913 867 679 129 773 158 231 477 118 825 976 616 395 715 870 229 687 20 160 543 231 977 792 942 680 81 257 314 374 354 522 464 410 462 311 82 648 299 604 588 527 131 48 32 682 295 832 131 35 246 148 256 970 510 668 305 356 265 5 581 436 411 864 59 444 603 392 778 42 91 740 229 774 6 253 729 182 649 666 313 198 65 540 392 420 132 623 155 119 781 263 752 385 809 906 790 270 960 983 881 320 122 764 861 806 555 665 191 160 192 304 129 586 207 635 300 776 281 301 724 619 64 627 934 943 380 521 910 67 902 863 500 140 227 33 51 707 523 596 572 816 715 314 843 861 694 996 850 945 592 699 912 284 361 518 529 850 4 118 248 976 827 412 586 817 305 561 731 877 450 988 563 901 23 554 873 277 703 290 53 613 713 77 45 850 68 202 717 70 865 194 2 420 240 819 581 193 353 138 890 579 138 483 131 9 237 427 60 82 163 842 538 213 648 759 837 122 262 657 334 569 668 381 695 553 388 814 952 292 290 243 399 495 32 178 770 436 26 467 431 456 762 446 462 277 398 557 98 434 893 606 91 972 176 923 85 592 960 420 662 354 990 859 699 96 814 640 263 776 437 886 447 879 236 571 693 289 708 121 792 228 273 620 408 644 190 973 348 708 461 748 835 530 790 63 26 219 881 540 947 142 337 882 521 647 833 437 643 6 995 499 530 688 83 491 675 190 259 858 975 281 814 396 435 354 54 165 110 219 861 40 15 866 10 418 520 858 903 526 113 811 62 140 84 466 316 144 54 926 714 814 470 315 615 177 200 691 704 901 301 569 568 249 767 124 161 56 695 263 924 283 575 539 368 383 436 872 809 631 267 119 146 551 178 909 450 742 992 940 314 439 252 499 540 868 156 249 605 156 986 422 981 146 882 246 651 865 746 661 767 41 948 298 356 857 865 637 520 480 215 553 155 414 33 849 797 214 248 189 362 903 965 602 615 652 222 955 858 239 889 427 331 225 477 247 646 705 10 136 38 304 587 75 159 717 702 653 509 15 167 628 918 900 322 492 587 260 241 65 647 882 855 906 755 335 881 490 700 774 249 285 714 12 688 509 665 352 482 776 799 477 931 540 104 726 28 140 759 594 19 368 52 995 480 946 53 725 115 362 726 65 925 805 348 295 206 959 144 151 869 551 996 517 22 580 853 471 424 569 311 936 12 72 83 971 354 226 717 986 294 110 835 52 877 161 435 887 474 350 7 364 962 991 445 498 156 59 967 832 796 751 753 270 994 294 123 941 422 214 920 245 672 816 652 120 460 86 610 640 848 992 70 419 575 798 837 358 856 270 883 975 944 279 767 222 156 356 772 475 880 883 733 176 449 310 8 804 465 470 276 528 809 8 250 160 691 124 621 74 766 626 938 316 499 668 417 603 435 515 4 483 121 408 204 359 941 893 130 480 920 281 875 319 633 920 7 935 244 388 235 872 224 377 12 480 493 570 969 395 460 738 997 516 386 772 559 935 401 83 711 794 321 407 511 53 862 889 797 472 584 18 695 995 636 710 77 388 296 157 934 584 285 451 920 111 780 787 166 868 903 247 860 378 319 490 943 556 164 254 378 982 85 107 195 504 903 516 911 575 509 836 31 189 119 549 911 343 661 330 752 196 483 571 619 353 285 746 454 936 288 895 271 82 863 832 547 597 731 506 706 85 873 220 532 158 879 682 380 778 299 729 162 730 511 265 935 34 293 285 923 113 563 253 367 159 848 484 633 127 124 164 303 177 478 806 99 26 779 989 268 103 751 496 424 880 596 11 797 53 104 948 917 231 576 968 867 950 858 713 878 119 148 227 58 400 1 297 655 215 691 435 601 978 333 654 293 491 672 836 553 403 371 21 397 954 31 460 106 989 328 931 610 185 570 32 773 746 658 607 316 61 444 844 157 814 648 781 623 246 489 432 232 201 542 863 344 439 646 537 621 525 51 773 401 380 546 185 136 505 321 238 956 567 565 605 457 854 169 113 956 941 643 537 628 187 62 472 709 192 442 419 264 923 694 309 13 82 178 429 411 144 994 531 85 883 922 551 647 351 824 269 508 417 138 586 923 182 170 563 457 641 862 424 473 589 694 142 772 983 972 761 266 471 985 97 67 861 758 584 214 740 783 959 780 834 361 782 544 690 400 527 438 272

+ 1
- 0
week09/inputmy1.txt Vedi File

@@ -0,0 +1 @@
1 1 2 2 3 1 2 1 2 3 1 2 1 2

Caricamento…
Annulla
Salva