Gnome3: Enable suspend/hibernate option without swap partition

Linux needs swap partition to suspend or hibernate. But there is a way to enable suspend and hibernate without creating a swap partition. The trick is to create a swap file instead of partition and informing linux to use this swap file instead of swap partition.

Install pmi(power management interface) package

sudo apt-get install powermanagement-interface

Now you should be able to suspend using either

sudo pm-suspend


dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

Peculiarly for me, the screen doesn’t lock when the PC suspends. Alternatively, you can lock and suspend using the following command

gnome-screensaver-command -l && dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

Enable suspend option in Gnome3 status menu

You can enable suspend option in Gnome3 status menu by installing the following extension.

SystemVerilog: Connect interface to pure Verilog modules

SystemVerilog interfaces gives us a very good tool to make the code cleaner and less error prone. If you have a group of ports that go together, you can group them into a single interface and reduce huge amount of code.

Thats great. But if you have a pure verilog module and want it to stay that way. How should we connect the interface to the pure Verilog module? Its easy as well. Just create an instance of a module and an instance of the interface. When you instantiate the verilog module use the interface’s members as module’s ports. Now you can drive your module through the interface or connect the module to another SystemVerilog module that accepts the same interface.

Golang: Call C code from Go code

Be it a library written in C or parts of your implementation you want to implement in C, it is very easy to call them from Golang.
All C functions, types, convenience function, etc are exported through C package in Golang. The C code can be directly embedded in Go code by writing it as comments directly above the statement that imports C package.

To run the above example execute the following command:

go run cgo1.go

You can also write C code in a separate .c file and access them in Go.

To run the above example execute the following command:

go run cgo2.go

To call a Go function in C code, export the Go function by writing the following snippet directly above the Go function:

//export func-name

All the exported Go functions can be accessed from C by including the auto-generated header file _cgo_export.h.

It should noted that this example won’t work unless you place the project under $GOPATH/src and execute go build on the project. For example move the two files to $GOPATH/src/cgo3 and execute the following commands:

go build cgo3