Open-source News

Intel AVX-512 A Big Win For... JSON Parsing Performance

Phoronix - Thu, 05/26/2022 - 19:00
In addition to the many HPC workloads and other scientific computing tasks where Intel's AVX-512 performance on their latest processor proves very beneficial, it also turns out AVX-512 can provide significant benefit to a much more mundane web server task: JSON parsing. The simdjson project that is focused on "parsing gigabytes of JSON per second" this week issued simdjson 2.0 and is headlined by an Intel-led contribution of AVX-512 support.

Intel Arc Graphics Get Linux Driver Fix To Support HDMI 4K@30

Phoronix - Thu, 05/26/2022 - 17:46
While from the outside it looks like DG2/Alchemist enablement under Linux is starting to settle down with Linux 5.19 beginning to expose compute support for these new Arc Graphics discrete GPUs, beginning to add in production PCI IDs, and other refinements, the enablement battle isn't yet over...

CUPS 2.4.2 Released With OpenSSL/LibreSSL Support Restored, AIX Revived

Phoronix - Thu, 05/26/2022 - 17:26
Since last year CUPS development shifted to the OpenPrinting project with Apple no longer pursuing feature development on this long-time open-source Unix print server. That led to the release then of CUPS 2.4 and work on this open-source print server has revived. Out today is CUPS 2.4.2 with a few new features...

Linux 5.19 KVM & Xen Changes Readied For This Next Kernel

Phoronix - Thu, 05/26/2022 - 17:09
Both the KVM and Xen changes are ready to go with the other code piling on for the Linux 5.19 merge window...

Document your source code with Doxygen on Linux

opensource.com - Thu, 05/26/2022 - 15:00
Document your source code with Doxygen on Linux Stephan Avenwedde Thu, 05/26/2022 - 03:00 3 readers like this 3 readers like this

When trying to familiarize yourself with someone else's project, you usually appreciate the comments left behind that help you understand the meaning of their code. In the same way, whenever you are programming, whether for yourself or for others, it is good practice to comment your own code. All programming languages offer a special syntax to mark a word, a line, or a whole section as a comment. Those areas are then ignored by the compiler or interpreter when the source code is processed. 

Comments don't take the place of documentation, but there is a way to use your comments to produce documentation easily. Meet Doxygen, an open source tool for generating HTML or LaTeX documentation based on comments in the code. Doxygen enables you to provide a comprehensive overview of the structure of your code without additional effort. While Doxygen is mainly used to document C++, you can use it for many other languages, like C, Objective-C, C#, PHP, Java, Python, and more.

To use Doxygen, you simply comment your source code in a syntax that Doxygen can read. Doxygen then walks through your source files and creates HTML or LaTeX documentation based on those special comments. The C++ example project below will illustrate how the source code is commented and how the documentation is generated from it. The example is available on GitHub, and I will also include references to different sections of the Doxygen manual and documentation.

[ Download now: Doxygen cheat sheet ]

Install Doxygen on Linux

On Fedora, Doxygen is available as a package. Open a terminal and run:

sudo dnf install doxygen

On Debian-based systems, you can install it by running:

sudo apt-get install doxygenUsage

Once installed, all you need is a project with Doxygen-compatible comments and a Doxyfile, a configuration file that controls the behavior of Doxygen.

Note: If you stick to the related example project on GitHub, you can omit the next step.

If there is no Doxyfile yet, you can simply let Doxygen generate a standard template. To do so, navigate to the root of your project and run:

doxygen -g

The -g stands for generate. You should now notice a newly created file called Doxyfile. You can invoke Doxygen by simply running:

doxygen

You should now notice two newly created folders:

  • html/
  • latex/

By default, Doxygen outputs LaTeX-formatted documentation as well as HTML-based documentation. In this article, I will focus only on HTML-based documentation. You can find out more about LaTeX output in the official Doxygen documentation, in the Getting started section.

Double click on html/index.html to open the actual HTML documentation. With a blank configuration, it probably looks like the screenshot below:

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

Now it's time to modify the Doxyfile and add some special comments to the source code.

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles Doxyfile

The Doxyfile allows you to define tons of adjustment possibilities, so I will describe only a very small subset. The settings correspond to the Doxyfile of the example project.

Line 35: Project name

Here you can specify the project name, which will be visible in the header line and the browser tab.

# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
# double-quotes, unless you are using Doxywizard) that should identify the
# project for which the documentation is generated. This name is used in the
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME           = "My Project"Line 47: Project brief description

The brief description will also be shown in the header but in a smaller font.

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.

PROJECT_BRIEF          = "An example of using Doxygen in C++"Line 926: Inclusion of subdirectories

Allow Doxygen to walk recursively through subdirectories to find source and documentation files.

# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.
# The default value is: NO.

RECURSIVE = YESLine 1769: Disable LaTeX output

If you are just interested in the HTML output, you can disable the LaTeX code generation using this switch.

# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.

# The default value is: YES.

GENERATE_LATEX = NO

After every change, you can run Doxygen again to check whether your changes have had the desired effect. If you just want to check which modification an existing Doxyfile has, invoke Doxygen with the -x switch:

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

As with the command diff, Doxygen displays only the differences between the actual Doxyfile and the template.

Special comments

Doxygen reads the sources and checks each file for special comments. Based on those comments and keywords, it builds up the HTML documentation. The anatomy of the special comments can be well explained using the header file of the class ByteStream, as shown in the GitHub example linked above.

I will look at the constructor and destructor as an example:

/*! @brief Constructor which takes an external buffer to operate on
*
* The specified buffer already exist.
* Memory and size can be accessed by buffer() and size().
*
* @param[in] pBuf Pointer to existing buffer
* @param[in] size Size of the existing buffer
*/

ByteStream(char* pBuf, size_t size) noexcept;

There are different flavors of formatting a special comment block. I prefer to start the comment in the Qt-style (/*!) and add an asterisk (*) before each line. The block then ends with an asterisk followed by a forward slash (*/). To get an overview of the different style options, refer to the Doxygen manual, in the section Documenting the code.

Comments in Doxygen are divided into two sections, a brief description and a detailed description. Both sections are optional. In the code sample above, the comment block refers to the following line of code, the declaration of a constructor. The sentence behind the @brief will be shown in the compact class overview:

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

After a blank line (blank lines are treated as paragraph separators), the actual documentation for the constructor begins. With the @param[in/out] keyword, you can mark the arguments passed to the constructor, and Doxygen will make a clear argument list from it:

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

Note that Doxygen automatically creates a link to the mentioned buffer() and size() method in the comment. In contrast, the comment before the destructor declaration won't have any effect on Doxygen as it is not recognized as a special comment:

// Destructor
~ByteStream();

Now you have seen 90% of the magic. By using a slightly modified syntax for your comments, you can convert them into special comments that Doxygen can read. Furthermore, by using a few keywords, you can advance the formatting. In addition, Doxygen has some special features, which I will highlight in the following section.

Features

Most of the work is already done via your regular commenting on the source code. But with a few tweaks, you can easily enhance the output of Doxygen.

Markdown

For advanced formatting, Doxygen supports Markdown syntax and HTML commands. There is a Markdown cheat sheet available in the download section of opensource.com.

Mainpage

Aside from your customized header, you will get a mostly empty page when you open html/index.html. You can add some meaningful content to this empty space by using specific keywords. Because the main page is usually not dedicated to a particular source code file, you can add an ordinary text file containing the content for the main page into the root of your project. You can see this in the example on GitHub. The comments in there produce the following output:

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

Automatic link generation

As noted above, Doxygen automatically figures out when you are referring to an existing part of the code and creates a link to the related documentation. Be aware that automatic link creation only works if the part you refer to is documented as well.

More information can be found in the official documentation, under Automatic link generation.

Groups

The ByteStream class has overloaded stream operators for writing (<<) and reading (>>). In the class overview in the Special comments section above, you can see that the operator declarations are grouped as Writing and Reading. These groups are defined and named in the ByteStream header file.

Grouping is done using a special syntax: You start a group with @{ and end it with }@. All members inside those marks belong to this group. In the header ByteStream.h it is implemented as follows:

/** @name Writing
* Operators for writing to the stream
* @{
*/

(...)

/** @}
* @name Reading
* Operators for reading from the stream
* @{
*/

(...)

/** @} */

You can find more information about grouping in the Doxygen documentation, under Grouping.

LLVM Support

If you are building with Clang, you can apply the flag -Wdocumentation to the build process to let Clang check your special comments. You can find more information about this feature in the LLVM Users Manual or in Dmitri Gribenko's presentation, both on the Clang website.

Where Doxygen is used

Doxygen was first released in 1997, so it has been already around for some years. Despite its age, many projects use Doxygen to create their documentation. Some examples are NASA's F Prime flight software framework, the image processing library OpenCV, and the package manager RPM. You can also find the Doxygen syntax in other areas, like in the documentation standards of the content management platform Drupal.

A caveat: One drawback of using Doxygen is that it outputs HTML documentation with the look and feel of web pages from the nineties. It is also hard to depict the architecture of meta and template programming using Doxygen. For those cases, you would probably choose Sphinx over Doxygen. Download the Doxygen cheat sheet now.

This widely used open source tool can generate documentation from your comments.

Image by:

Internet Archive Book Images. Modified by Opensource.com. CC BY-SA 4.0

Documentation Cheat sheets Linux Text editors What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Write C applications using Vely on Linux

opensource.com - Thu, 05/26/2022 - 15:00
Write C applications using Vely on Linux Sergio Mijatovic Thu, 05/26/2022 - 03:00 2 readers like this 2 readers like this

Vely is a tool for writing web and command-line applications in C. Vely combines high performance and the low footprint associated with C programming with ease of use and improved safety reminiscent of languages like PHP. It's free and open source software, and licensed under GPLv3 and LGPL 3 for libraries, so you can even build commercial software with it.

Vely works on major Linux distributions and processor architectures. You can use webservers, such as Apache, Nginx, or others, and databases such as MariaDB, PostgreSQL, and SQLite.

You can use Vely for web applications, command-line programs, as middleware, database applications, services software, data integration, IoT (Internet of Things), and anywhere else. It's well suited for the cloud, works easily in a container, and, due to low resource requirements, it's also a good choice when memory and processing power are at a premium.

Install Vely

To try Vely, install the Apache webserver and MariaDB database. You can use a different webserver and database, and the setup would be similar, but in this example, I use Apache and MariaDB.

Next, install Vely. On Linux use a package manager such as dnf or apt.

Stock tickers project

This example saves the names of stock tickers and their prices so you can view them in a list.

Start by creating stock.v file, and paste this code into it:

#include "vely.h"

void stock() {
   out-header default
   @
       @
       input-param action
       input-param stock_name
       input-param stock_price
       if (!strcmp (action, "add")) {
          // Add to stock table, update if stock exists
          run-query#add_data@db = "insert into stock (stock_name,\
              stock_price) values ('%s', '%s') on duplicate key \
              update stock_price='%s'" : stock_name, stock_price, \
              stock_price
           end-query
           error#add_data to define err
           if (strcmp (err, "0")) {
               report-error "Cannot update stock price, error [%s]", err
           }
           @
              @Stock price updated!
           @
       } else if (!strcmp (action, "show")) {
         // Show stock names and values
           @
               @
                   @Stock name
                   @Stock price
               @
               run-query#show_data@db = "select stock_name, \
                    stock_price from stock" output stock_name, \
                    stock_price
                   @
                       @
                       query-result#show_data, stock_name
                       @
                       @
                       query-result#show_data, stock_price
                       @
                   @
               end-query
           @
       } else {
           @Unrecognized request!
       }
       @
   @
}Build the database

For this example, create a database named dbstock, owned by user vely with the password your_password. These are arbitrary names, and in real life, you can use whatever values you want, as long as they're consistent throughout your code.

First, log in to the MariaDB database as root and execute this:

CREATE DATABASE IF NOT EXISTS dbstock;
FLUSH privileges;
CREATE USER IF NOT EXISTS vely@localhost IDENTIFIED BY 'your_password';
FLUSH privileges;
GRANT ALL privileges ON dbstock.* TO vely@localhost;
FLUSH privileges;
exit;

Now log in to MariaDB again and set the current database:

$ mysql -u vely -pyour_password

Now you can create the database objects needed for the application. You need a stock table in the dbstock database for this example.

USE dbstock;
CREATE TABLE IF NOT EXISTS stock (stock_name VARCHAR(100) PRIMARY KEY, stock_price BIGINT);

Finally, create a database configuration file named db so that your application can log into the database. You must call it db because that's what the code in stock.v uses. For instance:

[...]
run-query#add_data@db = "insert into stock ..."
[...]

The database name is preceded by the @ sign, in this case, @db, so the name of the database configuration file is db. As with other values, you can name your database configuration file whatever you want, as long as your code is consistent.

Here's the configuration for the db file:

[client]
user=vely
password=your_password
database=dbstock

The above is a standard MariaDB client options file. Vely uses native database connectivity, so you can specify any options a given database allows.

Programming and development Red Hat Developers Blog Programming cheat sheets Try for free: Red Hat Learning Subscription eBook: An introduction to programming with Bash Bash shell scripting cheat sheet eBook: Modernizing Enterprise Java Build the application

Next, you can create your Vely application. For this example, you're going to create a web app called stockapp:

$ sudo vf -i -u $(whoami) stockapp

This creates an application home under the Vely directory (/var/lib/vv) and performs the required application setup steps for you.

To build your application, use the vv command:

$ vv -q --db=mariadb:db stockapp

Here's what each option means:

  • -q builds an application
  • --db specifies the database to be used (mariadb:db, as specified in your configuration file)
  • stockapp is the application name

You can actually use any number of databases and different vendors in your application. This example is simple, though, so you only need one database. Vely has many other useful options you can use, but this is sufficient for now.

Configure web access

To access your application via a web browser or various web clients, you need to set up a webserver. It can be Apache, Nginx, or any other server that supports FastCGI proxying (most, if not all, webservers and load balancers do this). Here, I will set up Apache, but the setup is similar for other webservers.

The proxy and proxy_fcgi modules are installed and enabled by default on the Fedora install of the Apache web server, but you must enable them on Debian-based systems (like Ubuntu):

$ sudo a2enmod proxy
$ sudo a2enmod proxy_fcgi
$ sudo systemctl restart apache2

If you're not on a Debian-based system, you can enable an Apache module by adding it to the Apache configuration file or in a file in the /etc/httpd/conf.modules.d/ directory, depending on your distribution's configuration.

Next, open your Apache configuration file in a text editor. For example, on a Debian-based system:

$ sudo vi /etc/apache2/apache2.conf

On a Fedora system (including Red Hat Enterprise Linux and CentOS):

$ sudo vi /etc/httpd/conf/httpd.conf

Add this line to the end of the file:

ProxyPass "/stockapp" unix:///var/lib/vv/stockapp/sock/sock|fcgi://localhost/stockapp

Depending on your webserver configuration, there may be a better place to add the ProxyPass directive. For this example, though, the above is sufficient.

Save the file and restart the webserver. On Fedora-based systems:

$ sudo systemctl restart httpd

On Debian-based systems:

$ sudo systemctl restart apache2

In this case, you're connecting to your application through a socket, but you can use a TCP port instead (which comes in handy when your application resides in a container or something similar).

Run the application

Start the application server for your application:

$ vf stockapp

By default, this runs anywhere from 0 to 20 server processes for your application, depending on the load. When the user load is low, your application uses virtually no memory at all.

That was it! Navigate to http://127.0.0.1/stockapp?req=stock&action=add&stock_name=XYZ&stock_pri… in your web browser to see the application.

You've just updated the stock price for ticker "XYZ" to 440. Try different tickers and prices to build a list of stocks, which you can view with the URL http://127.0.0.1/stockapp?req=stock&action=show.

Congratulations, you've created your first Vely application, reverse proxied behind a web server.

You can also view the output without a graphical browser by using curl:

$ curl -s \
"http://127.0.0.1/stockapp?req=stock&action=add&stock_name=XYZ&stock_price=440"
$ curl -s "http://127.0.0.1/stockapp?req=stock&action=show"Run the application from the terminal

You can run your application from the terminal, too. A terminal command is always made along with the FastCGI application server, and it's named the same as your application (in this case, stockapp). It works exactly the same as the web app. You can write some requests to your application to be fulfilled as web requests and others to run from the command-line. To do that, you provide the request as environment variables. For instance, to output the list of stocks as HTML, type:

$ export REQUEST_METHOD=GET
$ export QUERY_STRING="req=stock&action=show"
$ /var/lib/vv/bld/stockapp/stockapp

To suppress HTTP headers, use:

$ export VV_SILENT_HEADER=yes
$ /var/lib/vv/bld/stockapp/stockappHow Vely works

Your application works by processing requests and sending back replies. A request is one of two HTTP methods: GET or POST.

A request always has a parameter req. In the example here, its value is stock. That means source code compiled from file stock.v is called automatically to handle such a request.

A source file like this can do many different things, all grouped logically under a single request. Here, you have another parameter action, which can have a value of add (to add or update a stock) or show (to show a list of stocks). You specify stock_name and stock_price parameters when adding or updating. Pretty easy stuff. Other than req, you can choose parameter names however you wish.

Looking at the code in stock.v, it's simple to follow. You use the input-param construct to get the values for your input parameters. Yes, those strange things in the C code that aren't C are Vely language constructs, and they do lots of useful stuff for you, such as run-query, which (as you might expect from the name) runs your queries. An easy one is @, which is an output construct. String handling is made simple and reliable without worrying about buffer overruns. Check out the full reference of Vely constructs to understand Vely's capabilities.

Vely converts all constructs in your code into pure C and makes a native executable that is very small and fast. Your application runs as several FastCGI server processes, which stay resident in memory while accepting and processing requests. All of these processes work in parallel.

For more info, see how Vely works and read more about Vely architecture.

Manage strings and memory

Vely has automatic garbage collection for all of its constructs. In fact, most of the time, you shouldn't need to free memory at all, so application development is even simpler. Leave that to Vely and enjoy computing free of memory leaks and far fewer memory issues than you might expect. String constructs such as write-string make it safe, fast, and easy to create complex strings just as they do simple ones.

FastCGI program manager

Even if you don't want to develop your own applications with Vely, you can use vf, Vely's FastCGI program manager, with any generic FastCGI program, not just those created with Vely.

Want to learn more about Vely?

I sometimes get asked about the project name. Vely is short for Vel(ocit)y. It's fast to program with, fast to understand code and maintain, and fast (and small!) at run time. It's even easy to containerize.

Check out the documentation at vely.dev, which features downloads and examples that go beyond the introduction this article provides.

Vely is an open source tool for writing web and command-line applications in C on major Linux distributions.

Image by:

Ray Smith

Programming What to read next How the C programming language has grown Install MariaDB or MySQL on Linux This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

EROFS, exFAT & EXT4 File-System Updates Arrive For Linux 5.19

Phoronix - Thu, 05/26/2022 - 15:00
In addition to the buttery Btrfs feature updates for the in-development Linux 5.19 kernel, the exFAT, EXT4, and EROFS file-system changes have all landed too so far in the first few days of the v5.19 merge window...

How to Encrypt Full Disk While Installing Ubuntu 22.04

Tecmint - Thu, 05/26/2022 - 12:22
The post How to Encrypt Full Disk While Installing Ubuntu 22.04 first appeared on Tecmint: Linux Howtos, Tutorials & Guides .

Linux distributions have done a great job to get additional protection by bringing full disk encryption and being the market leader. Ubuntu also is bundled with numerous features and disk encryption is one of

The post How to Encrypt Full Disk While Installing Ubuntu 22.04 first appeared on Tecmint: Linux Howtos, Tutorials & Guides.

Intel-Led Cloud-Hypervisor 24 Released For Rust-Written VMM

Phoronix - Thu, 05/26/2022 - 12:00
Cloud-Hypervisor as the open-source, Rust-based virtual machine monitor with a focus on security is out with its latest feature release. Cloud-Hypervisor started as one of many Intel open-source projects that last year shifted to under the Linux Foundation umbrella but still sees contributions from Intel as well as other industry leaders like Microsoft and Arm. Cloud-Hypervisor 24.0 is the newest version of this Rust VMM..

Linux 5.19 Networking Brings Big Improvements With Big TCP, PureLiFi, More Hardware

Phoronix - Thu, 05/26/2022 - 06:40
The networking subsystem updates have landed in the Linux 5.19 kernel with big updates to core networking code as well as a lot of individual driver work this cycle both for wired and wireless networking...

Pages