diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-05-19 17:24:26 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-05-19 17:24:26 +0000 |
commit | ebe07d59876f5928c4506c2dfb4800f63c83d2ea (patch) | |
tree | 89e0bcb7652159b1a49d8fda11c3c7890ad78263 | |
parent | b0293a61674ed329167aa49e7e563bf4a0e20106 (diff) | |
download | busybox-w32-ebe07d59876f5928c4506c2dfb4800f63c83d2ea.tar.gz busybox-w32-ebe07d59876f5928c4506c2dfb4800f63c83d2ea.tar.bz2 busybox-w32-ebe07d59876f5928c4506c2dfb4800f63c83d2ea.zip |
Patch from tito to replace shared memory usage with mlock(), slightly tweaked
by me.
git-svn-id: svn://busybox.net/trunk/busybox@15136 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | miscutils/hdparm.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index bf24a2d3a..457cf9670 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <sys/time.h> | 25 | #include <sys/time.h> |
26 | #include <sys/times.h> | 26 | #include <sys/times.h> |
27 | #include <sys/mount.h> | 27 | #include <sys/mount.h> |
28 | #include <sys/mman.h> | ||
28 | #include <getopt.h> | 29 | #include <getopt.h> |
29 | #include "busybox.h" | 30 | #include "busybox.h" |
30 | #include <linux/types.h> | 31 | #include <linux/types.h> |
@@ -1406,36 +1407,20 @@ static void do_time(int flag, int fd) | |||
1406 | flag = 1 time_device | 1407 | flag = 1 time_device |
1407 | */ | 1408 | */ |
1408 | { | 1409 | { |
1409 | char *buf; | ||
1410 | struct itimerval e1, e2; | 1410 | struct itimerval e1, e2; |
1411 | int shmid; | ||
1412 | double elapsed, elapsed2; | 1411 | double elapsed, elapsed2; |
1413 | unsigned int max_iterations = 1024, total_MB, iterations; | 1412 | unsigned int max_iterations = 1024, total_MB, iterations; |
1414 | unsigned long long blksize; | 1413 | unsigned long long blksize; |
1414 | RESERVE_CONFIG_BUFFER(buf, TIMING_BUF_BYTES); | ||
1415 | 1415 | ||
1416 | if (0 == do_blkgetsize(fd, &blksize)) { | 1416 | if (mlock(buf, TIMING_BUF_BYTES)) { |
1417 | max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB; | 1417 | bb_perror_msg("mlock"); |
1418 | goto quit2; | ||
1418 | } | 1419 | } |
1419 | 1420 | ||
1420 | if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1) | 1421 | if (0 == do_blkgetsize(fd, &blksize)) { |
1421 | { | 1422 | max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB; |
1422 | bb_perror_msg("shmget"); /*"could not allocate sharedmem buf"*/ | ||
1423 | return; | ||
1424 | } | ||
1425 | if (shmctl(shmid, SHM_LOCK, NULL) == -1) | ||
1426 | { | ||
1427 | bb_perror_msg("shmctl"); /*"could not lock sharedmem buf"*/ | ||
1428 | (void) shmctl(shmid, IPC_RMID, NULL); | ||
1429 | return; | ||
1430 | } | ||
1431 | if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1) | ||
1432 | { | ||
1433 | bb_perror_msg("shmat"); /*"could not attach sharedmem buf"*/ | ||
1434 | (void) shmctl(shmid, IPC_RMID, NULL); | ||
1435 | return; | ||
1436 | } | 1423 | } |
1437 | if (shmctl(shmid, IPC_RMID, NULL) == -1) | ||
1438 | bb_perror_msg("shmctl"); | ||
1439 | 1424 | ||
1440 | /* Clear out the device request queues & give them time to complete */ | 1425 | /* Clear out the device request queues & give them time to complete */ |
1441 | sync(); | 1426 | sync(); |
@@ -1505,8 +1490,9 @@ static void do_time(int flag, int fd) | |||
1505 | print_timing(total_MB, elapsed); | 1490 | print_timing(total_MB, elapsed); |
1506 | } | 1491 | } |
1507 | quit: | 1492 | quit: |
1508 | if (-1 == shmdt(buf)) | 1493 | munlock(buf, TIMING_BUF_BYTES); |
1509 | bb_perror_msg("shmdt"); /*"could not detach sharedmem buf"*/ | 1494 | quit2: |
1495 | RELEASE_CONFIG_BUFFER(buf); | ||
1510 | } | 1496 | } |
1511 | 1497 | ||
1512 | static void on_off (unsigned int value) | 1498 | static void on_off (unsigned int value) |