fibdrv.c
static ssize_t fib_read(struct file *file,
                        char *buf,
                        size_t method,
                        loff_t *offset)
{
#ifdef _TEST_KTIME
    fbn *fib = fbn_alloc(1);

    ktime_t kt = ktime_get();
    bn_fibonacci_seq[method](fib, *offset);
    kt = ktime_sub(ktime_get(), kt);

    fbn_free(fib);
    return (ssize_t) ktime_to_ns(kt);
#elif defined(_PERF_EVT)
#define REPEAT (200 * 1000)

    for (int i = 0; i < REPEAT; ++i) {
        fbn *fib = fbn_alloc(1);
        bn_fibonacci_seq[method](fib, *offset);
        fbn_free(fib);
    }

    return 0;
#elif defined(_FBN_DEBUG)
    pr_info("fibdrv_debug: <test bn_fib>");
    fbn *a = fbn_alloc(1);
    char *str = NULL;

    for (int i = 0; i < 5; ++i) {
        fbn_fib_fastdoublingv1(a, i);
        str = fbn_printv1(a);
        pr_info("fibdrv_debug: str %s\n", str);
        kfree(str);
    }
    fbn_lshift(a, 32);
    fbndebug_printhex(a);

    fbn_free(a);
    return 0;
#else /* normal read */
    fbn *fib = fbn_alloc(1);
    bn_fibonacci_seq[method](fib, *offset);
    char *str = bn_print[BN_PRINT](fib);
    ssize_t left = copy_to_user(buf, str, strlen(str) + 1);
    kfree(str);
    fbn_free(fib);
    return left;
#endif
}
/* calculate the fibonacci number at given offset */
calculate the fibonacci number at given offset
calculate the fibonacci number at given offset
static ssize_t fib_read(struct file *file,
                        char *buf,
                        size_t method,
                        loff_t *offset)
{
#ifdef _TEST_KTIME
    fbn *fib = fbn_alloc(1);
    ktime_t kt = ktime_get();
    bn_fibonacci_seq[method](fib, *offset);
    kt = ktime_sub(ktime_get(), kt);
    fbn_free(fib);
    return (ssize_t) ktime_to_ns(kt);
#elif defined(_PERF_EVT)
#define REPEAT (200 * 1000)
    for (int i = 0; i < REPEAT; ++i) {
        fbn *fib = fbn_alloc(1);
        bn_fibonacci_seq[method](fib, *offset);
        fbn_free(fib);
    }
    return 0;
#elif defined(_FBN_DEBUG)
    pr_info("fibdrv_debug: <test bn_fib>");
    fbn *a = fbn_alloc(1);
    char *str = NULL;
    for (int i = 0; i < 5; ++i) {
        fbn_fib_fastdoublingv1(a, i);
        str = fbn_printv1(a);
        pr_info("fibdrv_debug: str %s\n", str);
        kfree(str);
    }
    fbn_lshift(a, 32);
    fbndebug_printhex(a);
    fbn_free(a);
    return 0;
#else 
    fbn *fib = fbn_alloc(1);
    bn_fibonacci_seq[method](fib, *offset);
    char *str = bn_print[BN_PRINT](fib);
    ssize_t left = copy_to_user(buf, str, strlen(str) + 1);
    kfree(str);
    fbn_free(fib);
    return left;
#endif
}
static ssize_t fib_read ( struct file * file , char * buf , size_t method , loff_t * offset ) { #ifdef _TEST_KTIME fbn * fib = fbn_alloc ( 1 ) ; ktime_t kt = ktime_get ( ) ; bn_fibonacci_seq [ method ] ( fib , * offset ) ; kt = ktime_sub ( ktime_get ( ) , kt ) ; fbn_free ( fib ) ; return ( ssize_t ) ktime_to_ns ( kt ) ; #elif defined ( _PERF_EVT ) #define REPEAT  (200 * 1000) for ( int i = 0 ; i < REPEAT ; ++ i ) { fbn * fib = fbn_alloc ( 1 ) ; bn_fibonacci_seq [ method ] ( fib , * offset ) ; fbn_free ( fib ) ; } return 0 ; #elif defined ( _FBN_DEBUG ) pr_info ( " " ) ; fbn * a = fbn_alloc ( 1 ) ; char * str = NULL ; for ( int i = 0 ; i < 5 ; ++ i ) { fbn_fib_fastdoublingv1 ( a , i ) ; str = fbn_printv1 ( a ) ; pr_info ( " \n " , str ) ; kfree ( str ) ; } fbn_lshift ( a , 32 ) ; fbndebug_printhex ( a ) ; fbn_free ( a ) ; return 0 ; #else fbn * fib = fbn_alloc ( 1 ) ; bn_fibonacci_seq [ method ] ( fib , * offset ) ; char * str = bn_print [ BN_PRINT ] ( fib ) ; ssize_t left = copy_to_user ( buf , str , strlen ( str ) + 1 ) ; kfree ( str ) ; fbn_free ( fib ) ; return left ; #endif }
calculate the fibonacci number at given offset
calculate the fibonacci number at given offset
/* normal read */