Skip to content

Commit

Permalink
Introduce enum n2s_unit
Browse files Browse the repository at this point in the history
This patch does not change any functionality but makes num2str() slightly
easier to read.

Signed-off-by: Bart Van Assche <[email protected]>
  • Loading branch information
KAGA-KOKO committed Apr 18, 2018
1 parent 52e4c65 commit 41a8701
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,11 +833,11 @@ static int fixup_options(struct thread_data *td)
}
}

if (!o->unit_base) {
if (o->unit_base == N2S_NONE) {
if (td_ioengine_flagged(td, FIO_BIT_BASED))
o->unit_base = 1;
o->unit_base = N2S_BITPERSEC;
else
o->unit_base = 8;
o->unit_base = N2S_BYTEPERSEC;
}

#ifndef FIO_HAVE_ANY_FALLOCATE
Expand Down
6 changes: 4 additions & 2 deletions lib/num2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* @maxlen: max number of digits in the output string (not counting prefix and units, but counting .)
* @base: multiplier for num (e.g., if num represents Ki, use 1024)
* @pow2: select unit prefix - 0=power-of-10 decimal SI, nonzero=power-of-2 binary IEC
* @units: select units - N2S_* macros defined in num2str.h
* @units: select units - N2S_* constants defined in num2str.h
* @returns a malloc'd buffer containing "number[<unit prefix>][<units>]"
*/
char *num2str(uint64_t num, int maxlen, int base, int pow2, int units)
char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units)
{
const char *sistr[] = { "", "k", "M", "G", "T", "P" };
const char *iecstr[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
Expand All @@ -44,6 +44,8 @@ char *num2str(uint64_t num, int maxlen, int base, int pow2, int units)
base /= thousand[!!pow2];

switch (units) {
case N2S_NONE:
break;
case N2S_PERSEC:
unit_index = 1;
break;
Expand Down
18 changes: 10 additions & 8 deletions lib/num2str.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

#include <inttypes.h>

#define N2S_NONE 0
#define N2S_BITPERSEC 1 /* match unit_base for bit rates */
#define N2S_PERSEC 2
#define N2S_BIT 3
#define N2S_BYTE 4
#define N2S_BYTEPERSEC 8 /* match unit_base for byte rates */

extern char *num2str(uint64_t, int, int, int, int);
enum n2s_unit {
N2S_NONE = 0,
N2S_BITPERSEC = 1,
N2S_PERSEC = 2,
N2S_BIT = 3,
N2S_BYTE = 4,
N2S_BYTEPERSEC = 8,
};

extern char *num2str(uint64_t, int, int, int, enum n2s_unit);

#endif
6 changes: 3 additions & 3 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -4425,15 +4425,15 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
.prio = 1,
.posval = {
{ .ival = "0",
.oval = 0,
.oval = N2S_NONE,
.help = "Auto-detect",
},
{ .ival = "8",
.oval = 8,
.oval = N2S_BYTEPERSEC,
.help = "Normal (byte based)",
},
{ .ival = "1",
.oval = 1,
.oval = N2S_BITPERSEC,
.help = "Bit based",
},
},
Expand Down

0 comments on commit 41a8701

Please sign in to comment.