Giter Site home page Giter Site logo

fp_printk's Introduction

int to float point string

DESCRIPTION

This lib allows that you see in the kernel logs with sudo dmesg, number with float point.
Although we can work with arithimetic using the kernel_fpu_begin(), we dont can see this in dmesg.
int2fpstr convert the int to string for using in printk();

HOW TO USE

If you get my fork kernel, you has this lib and another changes.
But if you run the kernel from linus, then you need move this lib to kernel, compile and move binary result
to your /boot.

MOVE THE LIB

Clone this repository:
git clone https://github.com/GuilhermeGiacomoSimoes/fp_printk

Then you need move the int2fpstr.h to kernel source code:
mv int2fpstr.h ${KERNEL_SOURCE_TREE}/include/kernel

USE THE LIB

Then you import the lib in your module #include <linux/int2fpstr>. In the follow i show the simples use example:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>

#include <linux/int2fpstr.h>

MODULE_AUTHOR("SEU NOME <[email protected]>");
MODULE_DESCRIPTION("EXAMPLE int2fpstr use");

static int __init hello_world_init(void)
{
    int int_number = 1234;
    int count_decimal_places = 2;

    //str_number contain value = "12.34"
    char *str_number = int2fpstr(int_numer, count_decimal_places);
    pr_info("%s", str_number);
    kfree(str_number);

    return 0;
}

static void __exit hello_world_exit(void)
{
    pr_info("Good bye cruel world\n");
}

module_init(hello_world_init);
module_exit(hello_world_exit);

This is enough to use the int2fpstr. But if you want the unittests, then you read section follow.

RUN UNITTEST

You should move the int2fpstr_kunit.c to kernel source tree too:
mv int2fpstr_kunit.c ${KERNEL_SOURCE_TREE}/lib
Then, you need increment in the end files Makefile and Kconfig.debug the follow:
Makefile
obj-$(CONFIG_INT2FPSTR_KUNIT_TEST) += int2fpstr_kunit.o

Kconfig.debug

config INT2FPSTR_KUNIT_TEST
	tristate "Test int2fpstr library" if !KUNIT_ALL_TESTS
	depends on KUNIT
	default KUNIT_ALL_TESTS

To run this unittest in kernel linux, first you need dependency installs, and then run this:
./tools/testing/kunit/kunit.py run "int2fpstr"

PROBLEMNS

This lib have problemns.
The first is that you need use the kfree in the result after call int2fpstr function.
If you is a experient dev, you know that pointers is a source of bug.

fp_printk's People

Contributors

guilhermegiacomosimoes avatar

Stargazers

 avatar

Watchers

 avatar

fp_printk's Issues

C 2 rust

i'm skeptical with respect the pointer.
The fact that we need use kfree() to free memory alloc can a source of unsafe bugs.

i studing change this module to Rust, but the sintaxe of rust is not legible, nonetheless this fix the bug unsafe from the pointer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.