Linux guide for migration from Solaris to x86

Source: Internet
Author: User
Tags pthread mutex signal handler
Linux guide for migration from Solaris to x86

From: ibmdeveloperworks

Solaris is considered to be the most similar UNIX style to Linux, but for program migration, they are still quite distinct in areas such as memory ing, threads, and support for natural languages. This porting Guide provides some suggestions when you plan to port your program to Linux/x86 and helps you understand the differences between the R & D environment and the architecture.

Content:
Int get_stack (void ** stackptr) {* stackptr = 0; _ ASM _ volatile _ ("movl % ESP, % 0 ": "= m" (stackptr); Return (0 );}
Migration Plan
R & D environment
Unique differences between architecture and System
Conclusion

In Solaris, the following sample code allows you to obtain the stack pointer:
Listing 2. Getting the stack pointer on Solaris

. Section ". Text"

. Align 8

. Global my_stack

. Type my_stack, 2

My_stack:

! Save Stack pointer through 1st Parameter

St % sp, [% O0]

! Compute size of frame in return result Reg

Retl

Sub % FP, % sp, % O0

. Size my_stack, (.-my_stack)

On Linux x86, you can use a compare and swap operation to implement atomic locks. For example, the following is a simple implementation of the Compare and swap operations on Linux x86:
Listing 3. Compare and swap operations on Linux x86

Bool_t my_compareandswap (in int * PTR, in int old, in int new)

{

Unsigned char ret;

/* Note that sete sets a 'byte' not the word */

_ ASM _ volatile __(

"Lock/N"

"Cmpxchgl % 2, % 1/N"

"Sete % 0/N"

: "= Q" (RET), "= m" (* PTR)

: "R" (new), "M" (* PTR), "a" (old)

: "Memory ");

Return ret;

}

The atomic locking operation can be implemented as follows on Solaris iSCSI:
Listing 4. Atomic locks on Solaris

. Section ". Text"

. Align 8

. Global my_ldstub

. Type my_ldstub, 2

My_ldstub:

Ldstub [% O0], % O0! Atomic load set

Sll % O0, 24, % O0! Zero fill...

Retl! ... Result register

SRL % O0, 24, % O0! ... And retrn

. Size my_ldstub, (.-my_ldstub)

Endianness)
Since we use big-Endian and x86 uses little-Endian, you need to consider endianness.

The problem of endianness has become important in the following situations: porting an application that the customer's machine needs to communicate in a heterogeneous network environment and permanently saving the data to the disk, product tracking (the tracing information generated on the iSCSI platform must be correctly formatted on the x86 Platform), along with other related fields. IA-64 Linux kernel uses little-Endian by default, but can also use the byte order of big-Endian.

System Call
Solaris system calls use a different naming and signature mechanism that is unavailable on Linux. This is described in the "migration from Solaris to Linux on Power" guide. The following system calls can be used in RHEL4:

* Waitid
* Putmsg
* Putpmsg
* Getmsg
* Getpmsg

Curses Library
Linux's library functions for the xurses library are more similar to AIx than Solaris. For example, functions such as addwch are not supported in Linux. Some functions, such as mvchgat, are unavailable in Solaris. When you port the Code related to curses from Solaris to Linux, many codes need to be rewritten.

Terminal Io
The termio structure in Solaris is different from that in Linux. The termio structure in Linux has several more fields, and you can use them to configure the input and output speeds.

In Linux, The termio structure is defined in/usr/include/bits/termios. the definition of termio in Solaris is located in/usr/include/sys/termios. h.

IOCTL
The options available for executing IOCTL are different in Solaris and Linux. For example, to obtain the resource utilization, you can pass the piocusage to the ioctl system call:

Return_code = IOCTL ("/proc/ ", Piocusage, & buff );

In Linux, you must directly/ Directory to obtain relevant information. You cannot use the piocusage option on Linux. In both cases, the PID is the ID of the current process that is executing the command.

Another example is when you want to obtain the heap information of the process. To obtain heap information in Solaris, you can use the following method:

Return_code = IOCTL ("/proc/ ", Piocpsinfo, & psinfo)

In this Code, psinfo is a struct prpsinfo structure; prpsinfo. pr_size indicates the heap size of the process.

In Linux, the number of pages being used can be obtained from/proc/ /MEM and/proc/ /STAT. The page size can be obtained by calling getpagesize. The product of these two values (page number and page size) is the current heap size.

Getopt
In Linux, The getopt call follows the POSIX standard only after posixly_correct environment variables are configured.

If the environment variable posixly_correct is configured, the analysis of the parameter immediately stops when it encounters a non-option parameter (a parameter starting. All other parameters are interpreted as non-option parameters.

Differences between calling shell scripts
If the shell script uses the su command, a subshell is derived. Unlike Solaris, the su command does not derive a new shell in Solaris.

If you run the Su-root command on Linux, the output of the ps command is as follows:

30931 pts/4 00:00:00 Su

31004 pts/4 00:00:00 KSh

In this Code, 30931 is the ancestor of process 31004. You may need to modify some scripts that are affected by this relationship.

Device processing during restart
Since RHEL4, Linux has adopted the concept of the hot swapping subsystem udev. It supports configurable dynamic device naming. The device configuration is dynamically built upon every restart.

For example, if you have a new directory/dev/DSK, the system may not know its existence and the directory may be lost after being restarted. To avoid the loss of the/dev/DSK directory, you can create a/etc/udev/devices/DSK directory so that the system can maintain this information during restart, therefore, even after the system is restarted,/dev/DSK will still exist.

Kernel Parameters
In Solaris, kernel parameters can be configured in the/etc/system document. In Linux, kernel parameters can be modified using sysctl system calls. The modifiable parameters can be seen in/proc/sys/kernel. The support of procfs is required for the normal operation of sysctl.

Signal
The differences between signals have been detailed in "Technical Guide for porting applications from Solaris to Linux. Others are worth noting that Solaris has 38 signals, while Linux uses 31 signals, and the sigaction structure is also different. For example, in Linux, The sigaction interface is shown as follows: Listing 5. sigaction structure in Linux

Struct sigaction

{

/* Signal handler .*/

# Ifdef _ use_posix199309

Union

{

/* Used if sa_siginfo is not set .*/

_ Sighandler_t sa_handler;

/* Used if sa_siginfo is set .*/

Void (* sa_sigaction) (INT, siginfo_t *, void *);

}

_ Sigaction_handler;

# Define sa_handler _ sigaction_handler.sa_handler

# Define sa_sigaction _ sigaction_handler.sa_sigaction

# Else

_ Sighandler_t sa_handler;

# Endif

/* Additional set of signals to be blocked .*/

_ Sigset_t sa_mask;

/* Special flags .*/

Int sa_flags;

/* Restore handler .*/

Void (* sa_restorer) (void );

};

In Solaris, The sigaction structure is as follows:
Listing 6. sigaction structure in Solaris

Struct sigaction {

Int sa_flags;

Union {

# Ifdef _ cplusplus

Void (* _ handler) (INT );

# Else

Void (* _ handler )();

# Endif

# If defined (_ extensions _) | (_ stdc _-0 = 0 )&&! Defined (_ posix_c_source )&&! Defined (_ xopen_source) | (_ posix_c_source> 2) | defined (_ xpg4_2)

Void (* _ sigaction) (INT, siginfo_t *, void *);

# Endif

} _ Funcptr;

Sigset_t sa_mask;

# Ifndef _ lp64

Int sa_resv [2];

# Endif

};

The siginfo_t structure varies depending on the number of supported signals. For Linux, this can be found in the/usr/include/bits/signal. h document; for Solaris, this can be found in the/usr/include/sys/siginfo. h document.

Thread support and IPC
The publication on porting between Linux on power and Solaris has introduced the differences between the Solaris thread and the Linux POSIX thread (provided by the nptl library.

In my experience, if applications have already used POSIX Threads on Solaris, it is very easy to port them to Linux based on nptl threads. Some new features can be used in Linux, such as process shared mutex lock. Therefore, the IPC Mechanism-related code that uses the pthread mutex and conditional variables in Solaris can be used in Linux.

Natural Language Support
The supported code for natural languages in Solaris may be different from that in Linux, or they are just named differently. Most locales and code pages in Solaris have corresponding content in Linux.

Conclusion
Linux porting from Solaris to x86 is only a re-compilation process in most cases, or a slight modification to the compiler/linker switch. Sometimes you may need to modify the content specific to some platforms, such as locking, memory ing, threads, and so on. You should take a look at these differences and make a good planning for the transplantation to reduce the time required for the transplantation.

References

* You can refer to the original article in English on the developerworks global site.

* Download the xl c/C v7.0 compiler.

* GNU binutils is used to generate objects with xl c/C and GCC. The GNU binutils website provides detailed explanations.

* Download IBM developer kit for Linux, Java technology Edition version 1.4.2.

* The IBM Redbook AIX 5l porting Guide provides a detailed description of the issues that may occur when porting applications from other UNIX-based platforms to the AIX 5l operating system.

* Multithreaded programming guide describes POSIX and Solaris thread APIs, using synchronous objects for programming and compiling multi-threaded programs.

* Migrating to Linux kernel 2.6 discusses the migration of existing applications to the kernel of version 2.6 and the proprietary POSIX thread Library (nptl.

* Download performance inspector and obtain more information about the tool.

* Access the oprofile web site.

* Visit rpm.org to read more information about rpm.

* The developerworks migration topic can help developers find tools, technical articles, online tutorials, courses, forums, web sites, custom services, and other forms of help, this helps them quickly migrate various hardware platforms to Linux.

* "Technical Guide for porting applications from Solaris to Linux, version 1.0" (developerworks, December 2002) describes the differences between Solaris and Linux, and the contents of porting the application from Solaris to Linux.

* The Solaris to Linux porting Guide discusses the migration from the Red Hat Linux release of the 7.x series to Solaris.

* "Porting enterprise applications from UNIX to Linux" (developerworks, February 2005) discusses considerations for large-scale porting practices.

* The "migration from Solaris to Linux on power Guide" (developerworks, November 2005) is a supplement to this article, it provides some guidelines and resources for porting linux to a power-based system.

* "Using oprofile to fully understand performance" (developerworks, November 2003) describes how to use this tool to analyze performance without considering abnormal interactions between hardware and software.

* Find more resources for Linux developers in the developerworks Linux zone.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.