### Install and Enable GPE Handler Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/intel/io/acpica/changes.txt Example of installing a GPE handler, setting its type, and then enabling it. Note that AcpiInstallGpeHandler no longer automatically enables the GPE. ```c AcpiInstallGpeHandler (NULL, GpeNum, ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL); AcpiSetGpeType (NULL, GpeNum, ACPI_GPE_TYPE_RUNTIME); AcpiEnableGpe (NULL, GpeNum, ACPI_NOT_ISR); ``` -------------------------------- ### Initialize and Parse File with Sparse Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/tools/smatch/src/Documentation/sparse-README.txt This example demonstrates the minimal setup required to use the Sparse library for parsing a C file. It initializes the library, iterates through a list of files, and calls the sparse function for each. ```c struct string_list *filelist = NULL; char *file; action(sparse_initialize(argc, argv, filelist)); FOR_EACH_PTR_NOTAG(filelist, file) { action(sparse(file)); } END_FOR_EACH_PTR_NOTAG(file); ``` -------------------------------- ### LaTeX Theorem and Example Environments Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/io/qede/579xx/drivers/ecore/documentation/structure.tex Defines various theorem-like environments including Theorem, Problem, Question, Warning, Reminder, Exercise, Example, and Vocabulary. ```latex dummy dummysection ocrenumbox theoremeT[dummy]Theorem problemProblem[chapter] questionQuestion[chapter] WarningWarning[chapter] reminder[question]Reminder exerciseTExercise[chapter] blacknumex exampleTExample[chapter] blacknumbox vocabularyVocabulary[chapter] definitionTDefinition[section] corollaryT[dummy]Corollary ocrenum proposition[dummy]Proposition ``` -------------------------------- ### Build Smatch Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/tools/smatch/src/Documentation/smatch.txt Builds Smatch using the make utility. No installation process is provided; run Smatch from the build directory. ```bash make ``` -------------------------------- ### C Code Block Example Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/tools/smatch/src/Documentation/doc-guide.rst Demonstrates how to use the 'code-block' directive for C code with syntax highlighting. This is useful for including formatted code examples in documentation. ```rst .. code-block:: c int foo(int a) { return a + 1; } ``` ```c int foo(int a) { return a + 1; } ``` -------------------------------- ### Install Smatch Dependencies Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/tools/smatch/src/Documentation/smatch.txt Installs the necessary sqlite3 libraries for Smatch on Debian-based systems. ```bash apt-get install sqlite3 libsqlite3-dev libdbd-sqlite3-perl ``` -------------------------------- ### Example Test Case with Formatted Comments Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/tools/smatch/src/Documentation/test-suite.rst This example shows a C file with a comment block generated by the test-suite format command. It includes the check-name, check-command, check-exit-value, and output validation tags. ```c /* * check-name: bad assignment * * check-command: sparse $file * check-exit-value: 1 * * check-output-start bad-assignment.c:3:6: error: Expected ; at end of statement bad-assignment.c:3:6: error: got \ * check-output-end */ ``` -------------------------------- ### Example Usage of OSAL Linked List Functions Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/io/qede/579xx/drivers/ecore/documentation/osal.txt Demonstrates the usage of OSAL linked list functions, including initialization, pushing an entry to the head, and retrieving the first entry. ```c struct foo { osal_struct_t list_head; int x; }; osal_struct_list_t root; struct foo foo1, *tmp_foo; OSAL_LIST_INIT(&root) foo1.x = 10; OSAL_LIST_PUSH_HEAD(&foo1.head, &root); tmp_foo = OSAL_LIST_FIRST_ENTRY(&root, struct foo, list_head) ``` -------------------------------- ### Create and Configure a DTrace Consumer Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libdtrace_jni/java/docs/html/fast.html Instantiates a DTrace consumer, adds a listener for data events, and opens the consumer. This is the initial setup for interacting with DTrace from Java. ```Java Consumer consumer = new LocalConsumer(); consumer.addConsumerListener(new ConsumerAdapter() { public void dataReceived(DataEvent e) { System.out.println(e.getProbeData()); } }); consumer.open(); ``` -------------------------------- ### Linux Driver Examples Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/io/qede/579xx/drivers/ecore/documentation/ecore.tex Illustrates how multiple ecore instances can coexist within a single Linux system, used by different driver types like ethernet, fcoe, iscsi, roce, and diag utilities. Each driver may utilize the ecore for its specific initialization or operational needs. ```latex In linux there will be an ethernet driver, an fcoe driver, an iscsi driver, a roce driver and also a slim driver for the diag utility. All of these may exists in the same system. All of these will have an ecore instance incorporated in them. Either one of the drivers might use the ecore to initialize the device, or the sections of the device pertaining to that driver’s operation. A storage driver may use the ecore for storage specific purposes, such as the initialization and allocation of task context. ``` -------------------------------- ### Compile Java DTrace API Example Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libdtrace_jni/java/docs/html/fast.html Command to compile the TestAPI.java program, specifying the DTrace JNI JAR file in the classpath. ```shell javac -cp /usr/share/lib/java/dtrace.jar TestAPI.java ``` -------------------------------- ### Print Audit Data with XML Prolog and Ending Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/cmd/praudit/print_audit.txt This example demonstrates how to format audit data from standard input and print it to standard output in XML format, including a prolog and an ending. Ensure the output buffer is large enough to prevent ENOSPC errors. ```c print_audit_xml_prolog(); /* * Format audit data from stdin and print to stdout. */ retstat = print_audit(PRF_XMLM | PRF_ONELINE, NULL); if (retstat == 0) print_audit_xml_ending(); ``` -------------------------------- ### Compile, Enable, and Run a DTrace Program Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libdtrace_jni/java/docs/html/fast.html Compiles a D script from a file, enables it, and starts DTrace in a background thread. Macro arguments can be passed to the D script. ```Java consumer.compile(file, macroArgs); consumer.enable(); consumer.go(); ``` -------------------------------- ### Java Program to Create and Trace Process Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libdtrace_jni/java/docs/html/fast.html This Java code snippet demonstrates opening a consumer, creating a process to be traced, compiling a D script, enabling tracing, and initiating it with go(). ```Java consumer.open(); consumer.createProcess(command); consumer.compile(file); consumer.enable(); consumer.go(); ``` -------------------------------- ### Rx Packet Interrupt Handling Example Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/io/qede/579xx/drivers/ecore/documentation/ecore.tex Illustrates the flow when an Rx packet is received, including status block updates, interrupt generation, and driver processing. ```latex Assume an Rx packet is received by device. After FW places the packet in the Rx rings, it updates the status block of that Rx ring; This in turn is copied into host memory and an MSI-X interrupt for the appropriate Rx queue's status block is triggered. Driver reads the status blocks, scanning the indicies and identifies the interrupt is an Rx CQE consumer and handles the incoming packet. Assuming this is the only interrupt source [and there was also a single packet] driver than acks the status block. ``` -------------------------------- ### C Header Declarations Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/head/README.cplusplus.md This section shows unconditional C linkage declarations visible to both C and C++. It includes an example of a double-precision acos function declaration. ```c #include #ifdef __cplusplus extern "C" { #endif extern double acos(double); #ifdef __cplusplus } #endif ``` -------------------------------- ### C Function Documentation Example Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/tools/smatch/src/Documentation/doc-guide.rst Shows how to document a C function using Sparse's autodoc directive. This directive processes C-style doc-blocks to generate formatted API documentation. ```c /// // increment a value // // @val: the value to increment // @return: the incremented value // // This function is to be used to increment a // value. // // It's strongly encouraged to use this // function instead of open coding a simple // ``++``. int inc(int val) ``` -------------------------------- ### iASL Constant Folding Example Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/intel/io/acpica/changes.txt Demonstrates how the iASL compiler transforms arithmetic operations into Store operations for constant folding. This optimization simplifies parse trees. ```asl Add (2, 3, X) ==> is converted to: Store (5, X) X = 2 + 3 ==> is converted to: Store (5, X) ``` -------------------------------- ### Retrieving Singleton Aggregation Record Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libdtrace_jni/java/docs/html/fast.html Obtain the single record from a singleton Aggregation by getting the Aggregation, then the specific aggregation by name, and finally the record using Tuple.EMPTY. ```Java Aggregate a = consumer.getAggregate(); Aggregation total = a.getAggregation("total"); AggregationRecord totalRecord = total.getRecord(Tuple.EMPTY); ```